Wednesday, May 22, 2019

Multiple Post Buttons on asp.net core MVC

0



Solution 1:

 <input type="submit" value="Delete" formaction="Delete" formmethod="get"/>
 <input type="submit" formaction="Edit" formmethod="post" value="Edit"/>

This Method directly hits the Action defined in the formaction="actionName" and type of mehtod as defined in formmethod="methodName".


Solution 2:


<input type="submit" name="save" value="Save" />
<input type="submit" name="cancel" value="Cancel" />


 

There are two submit buttons - one with name attribute set to save and the other with name of cancel. When you click a particular button, its name and value is sent to the server. The ActionName() action needs to grab these values to detect which one was clicked.

 
       
[HttpPost]
public ActionResult ActionName(Customer obj,
                   string save,string cancel)
{
    if(!string.IsNullOrEmpty(save))
    {
        ViewBag.Message = "Customer saved successfully!";
    }
    if (!string.IsNullOrEmpty(cancel))
    {
        ViewBag.Message = "The operation was cancelled!";
    }
    return View("Result",obj);
Author Image

About Sushil
Soratemplates is a blogger resources site is a provider of high quality blogger template with premium looking layout and robust design

No comments: