Is there anything like .js.erb templates in ASP.NET MVC 3?
I am adding jQuery AJAX functionality to my MVC 3 site. When I use rails, I make an AJAX call using the $.getScript function then render a .js.erb which is executed on the client开发者_StackOverflow (e.g. http://railscasts.com/episodes/229-polling-for-changes ). Does MVC 3 have anything equivalent to Javascript views?
Yes it does
public ActionResult AjaxMethod() {
/* do stuff */
return PartialView("ViewName");
}
This will return the HTML of the above view to the calling ajax method
To return javascript to be executed directly in the client, like the Rails erb.js template, the best method would be to return a JavaScriptResult from the controller method
public ActionResult AjaxMethod() {
/* do stuff */
return JavaScript(script);
}
http://msdn.microsoft.com/en-us/library/system.web.mvc.javascriptresult.aspx
精彩评论