开发者

Is there anything like .js.erb templates in ASP.NET MVC 3?

开发者 https://www.devze.com 2023-02-11 19:02 出处:网络
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 (

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

0

精彩评论

暂无评论...
验证码 换一张
取 消