.net 4.5 razor - pass local variable to partial -


i'd able pass variable defined in 1 template another, included first template:

template 1:

@{string datetype= "beforethisyear"} @renderpage("template2.cshtml", datetype) 

template 2:

<input type="text" data-datetype="@datetype"/> 

unfortunately, yields error in template 2:

"the name 'datetype' not exist in current context" 

is there way pass variable without binding model first?

use viewbag:

template1:

@{ viewbag.datetype = "beforethisyear"; } 

template2:

<input type="text" data-datetype="@viewbag.datetype"/> 

this viewbag - passing view-only data around. note if data passing or should part of data model should use property of model it. given names of variables i'm guessing should part of model. note model isn't data class (i.e. entity representing row in table), model view in mvc conceptually represents data in view.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -