Can ViewData be referenced in a script block in ASP.NET MVC?
1 answer
If the script block is in an ASP.NET page, you can link to it ...
eg:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#group-edit-form').validate({
rules: {
title: {
required: true,
remote: '<%=Url.Action("ValidateGroupName", new { id = ViewData["GroupId"] }) %>?parentId=' + getParentId()
}
},
messages: {
title: {
required: getMessage (7002),
remote: '<%= ((MessagingModel)ViewData["Messages"]).GetMessage (9001) %>'
}
}
})
});
</script>
When a page is rendered by the runtime engine, everything in the <% ...%> block is evaluated regardless of its location on the page.
+2
source to share