[RESOLVED]passing hidden value from Ajax.BeginForm to control?

I have a CustomerModel in edit form with Ajax.BeginForm like below

@using (Ajax.BeginForm("Update", "Customer", new AjaxOptions() { UpdateTargetId = "message", HttpMethod = "Post", InsertionMode = InsertionMode.Replace, }))
{
    @Html.AntiForgeryToken()
    var cid = Model.CustId;
    Html.HiddenFor(model => model.CustId);
    
    ///// other proprety for edit
    <input type="submit" name="command" value="Update" class="button" />
}

i see that var cid get the correct value.

But on click of the Update button the action method is called but the Model doesn’t value for CustId.

What is wrong?

abhi0410

var cid = Model.CustId;

Html.HiddenFor(model => model.CustId);

The view engine will not render elements without the @ sign before them, and the var statement is only for use inside a <script> block. Change to this:

<script>
    var cid = "@Model.CustId";
</script>

@Html.HiddenFor(model => model.CustId)

Thank you very much. :-)

Sometime we do miss small stuff.

Leave a Reply