How to pass parameters to a partial view in ASP.NET MVC? -


suppose have partial view:

your name <strong>@firstname @lastname</strong> 

which accessible through child action like:

[childactiononly] public actionresult fullname(string firstname, string lastname) {  } 

and want use partial view inside view with:

@html.renderpartial("fullname") 

in other words, want able pass firstname ans lastname view partial view. how should that?

use overload (renderpartialextensions.renderpartial on msdn):

public static void renderpartial(     htmlhelper htmlhelper,     string partialviewname,     object model ) 

so:

@{html.renderpartial(     "fullname",     new { firstname = model.firstname, lastname = model.lastname}); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -