Question:
What's the best way to pass JSON data in javascript to an ASP.NET MVC strongly typed partial view?
Details:
I'm developing on a Win7 machine using VS2013 Express for Web.
I have a strongly-typed partial view using a class Workorder:
@model WebApplication1.Models.WorkOrder.WorkOrder
<h3>Partial Result:</h3>
Name: @Model.woName
<br />
SN: @Model.woSN
<br />
I make an AJAX call in my javascript on a Razor view page, that returns JSON data called "data":
function showPartial(data) {
@{
WorkOrder w = Json.Decode(<text>data</text>, WorkOrder);
@Html.Partial("PartialWOTop", w);
}
}
However, the view page won't process properly. I get the following error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1525: Invalid expression term '<'
Source Error:
Line 36: function showPartial(data) {
Line 37: @{
Line 38: WorkOrder y = Json.Decode(<text>data</text>, WorkOrder);
Line 39: @Html.Partial("PartialWOTop", y);
Line 40: }
Source File: c:\Users\xupd48act\Documents\Computer\Dev\VS Projects\WebApplication1\WebApplication1\Views\BacklogTracker\Index.cshtml Line: 38
Json.Decode()should be a JSON string, but your example has (unquoted) XML ... am I missing something?