开发者

Can you use MVC 2 Strongly Typed Helpers in Partial View?

开发者 https://www.devze.com 2022-12-18 14:40 出处:网络
I\'m trying to use the new strongly typed helpers. I\'ve inherited the Model in my Control: Inherits=\"System.Web.Mvc.ViewUserControl\"

I'm trying to use the new strongly typed helpers. I've inherited the Model in my Control: Inherits="System.Web.Mvc.ViewUserControl"

but intellisense isn't exposing the model and the page isn't happy with it if I force the code in. If I do it in a standard View all is good. This is what I'm expecting to be able to do:

开发者_如何学C
<%= Html.LabelFor(m => m.FirstName) %>

Can these helpers be used in Partial Views in this manner?

Lloyd


Yes.

All you need to do declare your partials as strongly typed to have access to the typed Model property:

Inherits="System.Web.Mvc.ViewUserControl<YourModel>"
0

精彩评论

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

关注公众号