curiouswebster
asked on
MVC3: How do I reference the model in the JavaScript for a page?
I see I can use the @ sign to do things like Url.Action(). But how do I reference the properties for the Model that the page is strongy typed to?
Thanks.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Sorry for the delay...
ASKER
"While JavaScript blocks declared inline on the view page can easily consume values from the model..."
My JavaScript is declared in the MVC3 Razor file thusly:
@section Scripts
{
@Html.Partial("Parts.Index
}
Does this change anything? I do not relish needing to dig into this JSon project described in the URL you'd attached. Is there an easier way?
For example, is there a built in Html Helper that can return the Model inside the JavaScript?
Something similar to...
function myFunc() {
var myVal = @Html.SomeHelper(model => model.MyValue);
or
var myVal = @HtmlHelper.SomeHelper(mod
}
Thanks.