public ActionResult Index(string submit)
{
Response.Write(submit);
return View();
}
当然,您可以评估该值,以使用开关块执行不同的操作。
public ActionResult Index(string submit)
{
switch (submit)
{
case "Save":
// Do something
break;
case "Process":
// Do something
break;
default:
throw new Exception();
break;
}
return View();
}
public ActionResult Register(string buttonSave, string buttonProcess, string buttonCancel)
{
if (buttonSave!= null)
{
//save is pressed
}
if (buttonProcess!= null)
{
//Process is pressed
}
if (buttonCancel!= null)
{
//Cancel is pressed
}
}
public ActionResult Create(string btnSubmit, string btnProcess)
{
if(btnSubmit != null)
// do something for the Button btnSubmit
else
// do something for the Button btnProcess
}
public ActionResult Save(FormCollection form)
{
if (this.httpContext.Request.Form["cancelButton"] !=null)
{
// return to the action;
}
else if(this.httpContext.Request.Form["submitButton"] !=null)
{
// save the oprtation and retrun to the action;
}
}
<button type="submit" name="Submit">Save</button>
<button type="submit" name="Cancel">Cancel</button>
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
return Page();
var sub = Request.Form["Submit"];
var can = Request.Form["Cancel"];
if (sub.Count > 0)
{
.......