[RESOLVED]Issue with URL when posting back

Hello, I have an Ajax form on my page, when i choose something from the dropdown I’m Automatically posting the form back to the controller to retrieve additional information thats associated with the chosen value.

Here is how my page is laid out.

@using (Ajax.BeginForm("New", "Item", new AjaxOptions { HttpMethod = "POST" }, new { @class = "form-horizontal", @id = "Form" }))
                                {
                                    <div class="step-content pos-rel" id="step-container">
                                        <div class="col-md-4 catergoiesLayout">
                                            <div class="col-lg-10">
                                                @Html.DropDownListFor(x => x.SelectedValueId, Model.SomeCategory, new { @ID = "drpSomeItems", @class = "form-control", size = "7", @style = "width:300px", onchange = "this.form.submit();" })
                                            </div>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="wizard-actions">
                                        <button class="btn btn-prev">
                                            <i class="ace-icon fa fa-arrow-left"></i>
                                            Save
                                        </button>
                                    </div>
                                }

when the value changes and posts back my URL looks like this

http://localhost:1470/item/new?Length=6

but I want it to look like

http://localhost:1470/item/new

my controller looks like this

 [HttpPost]
        public ActionResult New(ChooseCategoryViewModel model)
        {



return view(model);
}

There’s no overload of the Ajax.Beginform method that takes string, string, AjaxOptions, object (http://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxextensions.beginform%28v=vs.118%29.aspx).
You probably want the second-to-last overload and need to pass null to the routevalues parameter:

@using (Ajax.BeginForm("New", "Item", null, new AjaxOptions { HttpMethod = "POST" }, new { @class = "form-horizontal", id = "Form" }))

You also don’t need the @ in front of "id". You only need it before "class" because it is a C# keyword and cannot be used as a property name unless it is escaped with the @ sign: http://msdn.microsoft.com/en-us/library/x53a06bb.aspx

Leave a Reply