MVC Jquery go to controller action
Well, all good response so far, but using a magic string for building url just gives me the chills. I prefer to add an extension like this:
public static string GetUrl(this HtmlHelper, helper, string Action, string Controller, object RouteValues)
{
UrlHelper Url = new UrlHelper(HttpContext.Current.Request.RequestContext);
return Url.Action(Action, Controller, RouteValues);
}
and then in my js code use:
location.href = '@Html.GetUrl("Action", "Controller", new { foo=Model.Foo })';
It's more consistent, internally cares about routing, and gives me a centralized point where doing nasty things on Urls :)
Well, one more thing,
window.location = "whatever";
is good and works, still
location.href = "whatever";
is preferreable.
HTH
window.location.href = "/{controller}/{action}" //in your case, /employee/empl
This works because of the routes specified in your Global.asax.cs file. I suggest you read up on how this works as it's one of the fundamentals of MVC....