0

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" />
}
3
  • Are you wanting to add the latitude and longitude as route values rather that using hidden inputs Commented Sep 7, 2015 at 6:23
  • no i just want that when ever application open it submit auto and partial view shows Commented Sep 7, 2015 at 6:25
  • stackoverflow.com/a/20180627/1138165 this post might be helpful Commented Sep 7, 2015 at 6:27

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

9 Comments

problem is when i open the page and it will show button click on button then form is submit but i need it auto with out button
Sorry, I don't understand your comment. - My answer was addressing why you are getting ?length=4
now as you said i used null value now my partial view is open in new windows
Thats because you have not included jquery.unobtrusive-ajax.js (or have included the scripts in the wrong order or have duplicated them)
<script src="~/Scripts/jquery-1.10.2.min.js"></script> <script src="~/Scripts/bootstrap.min.js"></script> <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script> @RenderSection("script", required: false) here is order of the jqueery
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.