Oct 16, 2015

MVC which submit button has been pressed

input name="submit" type="submit" id="submit" value="Save" />
input name="submit" type="submit" id="process" value="Process" />
 
public ActionResult Index(string submit)
{
    Response.Write(submit);
    return View();
}
 
 
You can of course assess that value to perform different operations with a switch block
 
public ActionResult Index(string submit)
{
    switch (submit)
    {
        case "Save":
            // Do something
            break;
        case "Process":
            // Do something
            break;
        default:
            throw new Exception();
            break;
    }

    return View();
}.
 
 
 
 
 
  

No comments:

Post a Comment