0

I'm trying to a build a url in asp.net mvc but the object route values data come in later on through ajax. Basically what's happening is the following:

I click a button, which does an ajax call to the server to do some work. If the call is successful, I have to redirect to another page. I tried doing a redirect to action in the method but realized that won't work because it was ajax. So I decided to add the following in the success parameter to my ajax call:

window.location.href = '@Url.Action("view", "controller", new { data=data })';

but obviously this is compiled (or built or whatever) into a string when the page initially renders, and my data=data part is where the data is coming in after the ajax call.

is there another way to incorporate the data into my url?

1 Answer 1

1

The URL helper should give you the controller/action url on page render, then you can append the parameters using javascript like below.

window.location.href = '@Url.Action("view", "controller")?data='+data;
Sign up to request clarification or add additional context in comments.

3 Comments

the data is coming back null in the controller action method. but in the ajax completion success call theres data
Can you paste the URL in the browser address bar when the redirection occurs?
never mind it worked thanks, I had the wrong data type in the parameter

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.