i using attribute routing action of page. when post it, ajax form ignores action , controller defined in parameters , tries post same url method.
this action:
[allowanonymous] [httpget] [route("path")] public actionresult action() { return view(); } this post action:
[allowanonymous] [httppost] public jsonresult action(model model) { return json(true); } this view:
@using (ajax.beginform("action", "controller", new ajaxoptions() { httpmethod = "post", updatetargetid = "somediv" })) { @someinput <input type="submit" value="send" /> } this generated html:
<form action="/path" data-ajax="true" data-ajax-method="post" data-ajax-mode="replace" data-ajax-update="#somediv" id="form0" method="post"> <input value="submit" type="submit"> </form> when button clicked. post domain/path firing. why action defined ignored?
routes.maproute( name: "any name", url: "any url", defaults: new { controller = "your ajax controller name ", action = "your ajax action name" } ); or try this
routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); add last of routes in routeconfig.cs
Comments
Post a Comment