jeudi 17 décembre 2015

Action method parameter set to value of submit button

This is some legacy ASP.NET MVC3 code I've been asked to look at. It has an action method with two string parameters in addition to the model.

public ActionResult RequestUsername(StaffModel model, string request = null, string clear = null)

The form that calls this has two submit buttons:

<input type="submit" class="button" title="Request username" value="Request Username" name="request" />
<input type="submit" class="button" title="Clear form" value="Clear" name="clear" />

If I click the first one, the method parameter called 'request' is set (to "request"). If I click the second button, the method parameter called 'clear' is set (to "clear"). I can't see any custom code that would do this, so I think it must be something in the framework.

My question is: what is doing the mapping between the name attribute of the button being clicked, and the action parameter?

Thanks

Aucun commentaire:

Enregistrer un commentaire