开发者

MVC 3 using a Model inside a Razor layout page?

开发者 https://www.devze.com 2023-03-06 19:12 出处:网络
Is it possible to use a Model inside the layout page? For instance, we have a a model that contains several forms to be rendered onto the page. One form is a search form used 开发者_Python百科to searc

Is it possible to use a Model inside the layout page? For instance, we have a a model that contains several forms to be rendered onto the page. One form is a search form used 开发者_Python百科to search our site and we would like to add that to the layout page. Now we want to take advantage of the html.editorfor helper to print out the form. The search form can differ a bit depending on what view that is presented (which is the reason to why we don't want to type it in html). So how can i pass this search for to the model and still take advantage of the html helper to print it out?


Edit: Corrected :-)

Yes, absolutely.

Just put:

@inherits WebViewPage<MyModelName>

at the top of the layout page, and this will set the base class, with the Model property typed as MyModelName.

0

精彩评论

暂无评论...
验证码 换一张
取 消