How to fetch HTML Input Id in code behind ASP.Net MVC ? Either on Controller or on Model ?
view / .cshtml
<button type="submit" id="previewButton" >Preview</button>
JQuery : - This will not be in use.
$("button").click(function ()
{
var btn = this.id;
alert(btn);
}
In Controller :
[HttpPost]
public ActionResult New(MyViewModel viewModel, string clickedButton)
{
var vm = clickedButton;
return View(vm);
}
MyViewModel
public string clickedButton { get; set; }
idattribute). Make the button<button type="submit" name="clickedButton" value="xxxx">Preview</button>, and if you click that button, the value of your parameter will be "xxxx"string clickedButtonparameter (the value of the property will be bound with the value of the button).nameattribute which must match the name of the parameter (or model property), and avalueattribute (and the parameter or property will be bound with that value)