MVC 4 JsonResult rendering raw string instead of View

290 Views Asked by At

This is a real beginner question and hopefully you would be able to help me with a quick answer.

When I call my action of type JsonResult the view renders as raw Json and not as the expected defined view that I have created.

This is all that I see in the browser:

[{"Name":"xx","Description":"xx","Address":"xx","Town":"xx","PostCode":"xx","Enabled":true,"pkId":1},{"Name":"xx","Description":"xx","Address":"xx","Town":"xx","PostCode":"xxx","Enabled":true,"pkId":3}]

Here's my action:

public JsonResult SubmitFeedback()
    {
        PropertyInspectionContext context = new PropertyInspectionContext();
        var prop = context.Property;
        return Json(prop, JsonRequestBehavior.AllowGet);

    }

Thanks,

1

There are 1 best solutions below

0
On BEST ANSWER

If you have created JsonResult ( Json) in return so it is return JsonString.

If you want View should be return with Html markup and model combine then you should have to return View Result.

public ActionResult SubmitFeedback()
    {
        PropertyInspectionContext context = new PropertyInspectionContext();
        var prop = context.Property;

        //return Json(prop, JsonRequestBehavior.AllowGet);
        return View(your view name,prop);   

    }