Calling Action method from javascript
If I need to call some action method of a controller from within javascript code I can call it just passing the href, right? Something like that:
$.colorbox({ href: '/Calendar/SessionPropertiesEditbox?starts='+start+' })
That's not gonna work. The problem is the exact link should include the domain name also. But you don't know what the domain name would be. It could be "http://localhost:7741" today, tomorrow could be absolutely different.
So ho开发者_StackOverflow中文版w to emulate ActionLink behavior in javascript code?
You are incorrect; that will work.
It's a domain-relative path, so the browser will automatically add the current domain.
If your application is not running in the domain root, it will not work, since it will look in the domain root.
If so, you'll need to call Url.Action
and pass its result to your Javascript.
In a Razor view, that would look like
<script>
var url = "@Server.JavaScriptStringEncode(Url.Action(...))";
</script>
Try to use JsAction http://jsaction.codeplex.com
精彩评论