Its very common to have three Edit Actions in one controller all with the same name
- Get - Gets the original
- Post - Saves the users changes to the database
- Delete - Deletes the record from the database
This is done by using attributes HttpGet, HttpPost and HttpDelete. The post is triggered by the normal submit button and the delete is trigger by a submit button with a name="X-HTTP-Method-Override" and a value="Delete".
The problem is this only works for English, as "Delete" is the text of the button. If you change delete to French, "Supprimer", the action with the HttpDelete attribute will not be called. So how do you localize HttpDelete.
Controller:
[HttpGet]
public ActionResult Edit(TId id, TSeq seq)
{
...
}
[HttpPost]
[ValidateOnlyIncomingValuesAttribute]
public ActionResult Edit(TEntity editEntity)
{
...
}
// X-HTTP-Method-Override Delete Action
[HttpDelete]
public ActionResult Edit(TId id, TSeq seq, TEntity editEntity)
{
...
}
cshtm Button:
<input type="submit" name="X-HTTP-Method-Override" value="@GlobalResources.Delete" formnovalidate="" class="btn btn-default" onclick="return confirmDelete('@GlobalResources.PromptBeforeDelete')" />