User1400794712 posted
Hi id3ma,
If you just want to pass some hidden fields to the HttpPost method, you can use JQuery Ajax. For example:
@model Test.Models.Category
@{
ViewBag.Title = "Associate";
}
<h2>Associate</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@*Hidden Fields*@
@Html.HiddenFor(model=>model.CategoryID)
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CategoryName, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.CategoryName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CategoryName, "", new { @class = "text-danger" })
</div>
<input type="submit" value="Edit" class="btn btn-default" id="Edit"/>
}
@section scripts{
<script>
$("#Edit").click(function (e) {
e.preventDefault();
var token = $('input[name="__RequestVerificationToken"]', $("form")).val();
$.ajax({
url: '@Url.Action("Associate","Demo")',
data: {
__RequestVerificationToken: token,
ID: $("#CategoryID").val()
},
method: 'POST',
success: function () {
alert("s");
}
})
})
</script>
}
Then in HttpPost method:
[HttpPost]
public ActionResult Associate(int? ID)
{
return View();
}
If you have any confusion, please feel free to post back.
Best Regards,
Daisy