0

Migrating my brain from WebForms to MVC, I want to:

1) click on a button, that will 2) execute some javascript, that will 3) open a new window (or tab, whichever the browser is set for), that will show an existing view from the same solution, and 4) have that view execute some data loads

I'm stuck on 3 and 4

3) in this:

function foo(){
var wrkURL = globalURLVarFromViewOneThatPointsToViewTwo
window.open(wrkURL,"_blank")
}

how do I specify the URL of another existing view (ViewTwo) in the same solution? Is there a helper that I can call within ViewOne that will create that URL within the calling view, and load into globalURLVarFromViewOneThatPointsToViewTwo? Or, if I have to spell out the URL for ViewTwo, what does that syntax look like?

4) How do I get ViewTwo to automatically do some data operations (like find data for a FlexGrid) before or immediately on being displayed? I know how to do an Ajax call to a controller/action on document.ready; is there some other way of calling a controller/action and loading the view.bag, as the view is displayed, instead?

2 Answers 2

2

For building the Url, look at the URL helper:

@Url.Action("ActionName", "Controller", new { 
    someVariable= someData
}) 

As for #4, notice that when I'm building the URL, I'm building it with route parameters. These parameters will be passed to your controller's action and you can do what you please with them (just make sure routing is configured so you'll get the appropriate match for your intended action).

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

2 Comments

Thanks for the input. Re the solution to #4, I'm not sure this addresses the need "to perform data load on view display". Is there syntax for getting the view to automatically execute a controller action when it first loads? Or does that have to be done from the calling controller, before the view loads?
Doh! I see. I can call whatever controller I want from JS. That can have the "data load" operations I need. OK, I think this is done.
2

Actually action methods respond to URLs. So you need to create a URL for the action method. Make sure you return that specific view from the action.

var wrkURL = '@Url.Action("SomeAction", "SomeController")';

1 Comment

Doh! This was simple; I did not get that it would work with window.open. Thanks.

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.