什么是@ Html.ValueFor(X => x.PropertyName)之间的差异,@ Model.PropertyName [英] What is the difference between @Html.ValueFor(x=>x.PropertyName) and @Model.PropertyName

查看:119
本文介绍了什么是@ Html.ValueFor(X => x.PropertyName)之间的差异,@ Model.PropertyName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Html.ValueFor(x=>x.PropertyName) 
@Model.PropertyName

好像这两个剃须刀的命令做同样的事情。有没有使用一个比其他任何特殊情况或利益?

It seems like these two Razor commands do the exact same thing. Is there any special circumstance or benefit of using one over the other?

推荐答案

ValueFor 将调用存在的渲染属性具有类型的模板。默认情况下这个模板可以是的ToString一样简单(),但您可以定义什么作为模板。

ValueFor will invoke the template that exists for rendering the type that the property has. By default this template may be as simple as ToString(), but you can define anything as the template.

@ Model.PropertyName 就干脆present值作为字符串。

@Model.PropertyName will simply present the value as string.

这篇关于什么是@ Html.ValueFor(X => x.PropertyName)之间的差异,@ Model.PropertyName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆