1

I have a problem calling an action using javascript. So, I calculate a distance between two latitudes and longitudes. Now, If that distance is greater than 100 miles I want to call "distant" action in home controller that would return different view, but if it's less I would like to stay with index action. Any ideas? Thank you!

6
  • What are you returning? Partial view? JSON? Commented Jul 27, 2011 at 19:22
  • Partial view. I added all the javascript in Home/index view is it the right place to do it? Commented Jul 27, 2011 at 19:29
  • Ideally you'd move the javascript into a separate file and keep your view as clean as possible. Commented Jul 27, 2011 at 19:32
  • if(distance > 100){ $.ajax({ url: "Home/Distant" }) } doesn't do anything, I still keep getting index view. I am sure that distance is greater than 100 though. Commented Jul 27, 2011 at 19:37
  • are you wiring up your success and error handlers? Commented Jul 27, 2011 at 19:43

1 Answer 1

4

Why can't you just do something like:

if (distance > 100) {
  $.ajax({url: 'distantURL', ...});
} else {
  $.ajax({url: 'closeURL", ...});
}

Without additional information, it's tough to give a more detailed and/or accurate answer.

EDIT: Here's a nice walk-through tutorial of loading a partial view via jQuery's $.ajax() function, which sounds like what you want to do.

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

Comments

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.