简体   繁体   中英

ASP.NET MVC partial view parameter from jquery

I am working on Location Detector Module of the Project

Detecting latitude and longitude using jQuery, there is a button that submit the ajax form to the action and that action return partial view.

How can I send auto parameter to the action and get the partial view

I used

document.getElementById("fmDis").submit();

but it creates ?length=4 in url

I am using ajax form with hidden values

using (Ajax.BeginForm("DistanceFound", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "partial" }, new { id = "fmDis" }))
{
    <input type="hidden" id="lat" name="lat" />
    <input type="hidden" id="lon" name="lon" />
    <input type="submit" />
}

You using the wrong overload of Ajax.BeginForm where the second parameter ( "Home" ) is being added as a route value. It needs to be this one

using (Ajax.BeginForm("DistanceFound", "Home", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "partial" }, new { id = "fmDis" }))

Note your hidden inputs do not have a value attribute, so I assume you are setting their values in a script before you submit the form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM