asp.net mvc - can we identify the id of a button in mvc on httppost -


i have view has 2 submit buttons(save&close,save&new).

 <span>     <input type="button" value="save&new" name="save&new" id="savenew" />     </span>     <span>     <input type="button" value="save&close" name="save&close" id="saveclose" />     </span>     <span> 

when hit 1 of these buttons,the model data goes controller , hits post action

    [httppost]     public actionresult company(myproject.models.company company)     {         return view();     } 

now company object has complete model data(such company.phonenumber,company.state etc etc). want identify id of button(either save&new or save&close) user clicked. both buttons click leads same actionresult(company) , want identify button click request came. cannot use @html.actionlink instead of input type =submit. need know id out using jquery.

give buttons same name:

<button type="submit" name="btn" value="save_new" id="savenew">save&amp;new</button> <button type="submit" name="btn" value="save_close" id="saveclose">save&amp;close</button> 

and controller action take btn string parameter.

[httppost] public actionresult company(myproject.models.company company, string btn) {     if (btn == "save_new")     {         // form submitted using save&new button     }     else if (btn == "save_close")     {         // form submitted using save&close button     }     else     {         // form submitted using javascript or user         // pressed enter key while being inside of input fields     }      return view(); } 

also notice have used submit buttons (type="submit") whereas in example have used simple buttons (type="button") not allow submitting html form.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -