Simple question about ActionResult RRS feed

  • Question

  • User562699594 posted

    I have a view with a form that has both the public ActionResult Associate(), and the [HttpPost] public ActionResult Associate().

    Right now the HttpPost is Binding to a model class and I don't want to do that.  I just want to pass some hidden fields.

    How would I do that withing the Bind part of the ActionResult?


    Thursday, December 7, 2017 10:11 PM

All replies

  • 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";
    @using (Html.BeginForm()) 
        @*Hidden Fields*@
        @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" })
        <input type="submit" value="Edit" class="btn btn-default" id="Edit"/>
    @section scripts{
            $("#Edit").click(function (e) {
                var token = $('input[name="__RequestVerificationToken"]', $("form")).val();
                    url: '@Url.Action("Associate","Demo")',
                    data: {
                        __RequestVerificationToken: token,
                        ID: $("#CategoryID").val()
                    method: 'POST',
                    success: function () {

    Then in HttpPost method:

    public ActionResult Associate(int? ID)
        return View();

    If you have any confusion, please feel free to post back.

    Best Regards,


    Friday, December 8, 2017 2:02 AM