c# - How to remove the ID part in my form html tag when using Html.Beginform helper? -


i'm using form helper so:

 @using (html.beginform("upload", "file", formmethod.post, new { enctype = "multipart/form-data"}))  } 

my controller's action is:

[httppost] public actionresult upload(httppostedfilebase file) { } 

when @ html, generated form tag is:

<form action="/file/upload/123123" enctype="multipart/form-data" method="post"> </form> 

for reason including id part of url during request. how can remove just:

action="/file/upload" 

also understand, change action declaration also?

i don't understand why want remove id part.

but answer question, yes can.
here how it.

try first based on html.beginform(string actionname, string controllername).

@using(html.beginform("upload", "file") { } 

if doesn't work (or) still putting in id value, try using this
html.beginform(routevaluedictionary routevalues).

@using(html.beginform(new routevaluedictionary { { "controller", "file" }, { "action", "upload" } }) { } 

with that, point totally different controller's action method.
lets on filecontroller, can set form tag post controller's action method.

@using(html.beginform("anotheruploadaction", "anothercontroller")) { } 

even better, can use beginrouteform( ) method if want reference url route name.

routes.maproute(     name: "my-route-name",     url: "routeupload",     defaults: new { controller = "anotherclass", action = "upload" } );  @using(html.beginrouteform("my-route-name")) { } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -