views:

62

answers:

3

hey there - I'm trying to use asp.net mvc for some things as usual, but I've got a bit of a quandry.

At one point in my application, I need to load a view and pass a specific model through it - this isn't a huge deal, except that it relates to the existing model. Now then, RenderPartial doesn't work because that only passes a model and doesn't actually hit the controller - I need to run back to the controller to pass the model through the ActionResult so that its contents can be returned.

So I thought I would use jQuery. #('...').load('/controller/action') has worked in the past, so why not now? But I need to pass a parameter through it. I've tried simply adding...

load('/controller/action/' + <%= Model.Parameter %>) and it didn't take - so does anyone know how to do this? (or perhaps a better way to do it?)

A: 

Could you be more specific? What didn't work about it?

If you used the exact statement that you put in your question, there's one problem with it in that you haven't enclosed the asp tag in single quotes, so jquery would be interpreting the rendered value as a variable, and not as a literal string.

...load('/controller/action/' + '<%= Model.Parameter %>')
womp
+2  A: 

You can use MVC Futures / ASP.NET MVC 2 which has a RenderAction method, allowing you to go back to the controller. Also you can pass in the model you need for your partial view as a property of the parent view model, my current method. Or store the new model in the ViewData, but this isn't very strongly typed and not recommended.

Yuriy Faktorovich
Is there an MVC Futures for ASP.NET MVC 1.0? It isn't listed that I can find.
Stacey
http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471
Yuriy Faktorovich
+1  A: 

Hey,

$.load('<%= Url.Action("actionname", "ctlrname", new { param = Model.Parameter }) %>'); will work. Or, the MVC futures has a RenderAction method that allows you to render an action inline.

Brian