Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question
up vote 1 down vote accepted

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).

share|improve this answer
    
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? – wayfarer Feb 15 '14 at 21:08
    
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. – wayfarer Feb 15 '14 at 22:17

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")';
share|improve this answer
    
Doh! This was simple; I did not get that it would work with window.open. Thanks. – wayfarer Feb 15 '14 at 21:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.