System.Web.MvcController.Json
returns an object of type System.Web.Mvc.JsonResult
.
You are passing this object as a model to your view. So you should declare your model as
@model System.Web.Mvc.JsonResult
But this is not usefull.
If you want to serialize an object as JSON for use in your view, then use a serializer for that. The model will be a string then.
Some serializers you can use:
- JavaScriptSerializer is used within
System.Web.Mvc.JsonResult
in the assembly System.Web.Extension - Json.NET is popular and has great performance
- DataContractJsonSerializer comes with WCF and is not the greatest at all
// action code in controller
string json = JsonConvert.SerializeObject(project)m
return this.View(json);
// in the view
<script>
var json = @Html.Raw(this.Model);
</script>
EDIT: you can also pass the project
variable as the view's model. You will be able to use the project
variable within the view and serialize it as JSON in there.
If you want to return JSON for an AJAX call, then
return this.Json(project);
You will have to rely on javascript to get the JSON with an AJAX request.