Asp.net mvc 4 MVC4What';模型和模型的区别是什么
我差不多两年没有用C语言编码了,所以我的知识丢失了很多。Asp.net mvc 4 MVC4What';模型和模型的区别是什么,asp.net-mvc-4,model-view-controller,Asp.net Mvc 4,Model View Controller,我差不多两年没有用C语言编码了,所以我的知识丢失了很多。 我在一个项目中工作,我发现我不能使用模型在视图中做一些数据绑定的事情。在MVC4+中,是否将@model[type]更改为WebPage.model?我只熟悉Mvc3-。如果给出示例项目,我将非常感谢。@model用于在视图页面中“导入”模型,而@model表示导入的模型,是您检索其属性的地方 请参见下面的示例: @model MeuExemploMVC.Models.CarrinhoComprasViewModel @{ Vi
我在一个项目中工作,我发现我不能使用模型在视图中做一些数据绑定的事情。在MVC4+中,是否将
@model[type]
更改为WebPage.model
?我只熟悉Mvc3-。如果给出示例项目,我将非常感谢。@model
用于在视图页面中“导入”模型,而@model
表示导入的模型,是您检索其属性的地方
请参见下面的示例:
@model MeuExemploMVC.Models.CarrinhoComprasViewModel
@{
ViewBag.Title = "Purchase Cart";
}
<h2>@Model.Mensagem
</h2>
<fieldset>
<legend>Purchase Cart</legend>
<table>
<caption>Products</caption>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
@foreach (var product in Model.Products) {
<tr>
<td>@product.Name</td>
<td>@product.Price</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td><strong>Total</strong></td>
<td>@Model.TotalPrice</td>
</tr>
</tfoot>
</table>
</fieldset>
@model MeuExemploMVC.Models.CarrinhoComprasViewModel
@{
ViewBag.Title=“采购车”;
}
@模特
购物车
产品
产品
价格
@foreach(模型产品中的var产品){
@产品名称
@产品价格
}
总计
@模型总价
这里您可以看到,@model
只是将模型对象导入页面,而@model
则从检索到的模型中获取实际值
是CodeProject的一个教程,说明了这种差异。请注意,这里提供了一个示例代码。您的意思是在视图中使用(以及与Razor代码一起使用)?是的,在mvc4+中,删除@model?不要删除
@model yourClass
。定义视图中使用的模型,然后使用model
访问其属性的值,例如@model.someProperty
,或在html帮助程序中,例如@html.DisplayFor(m=>m.someProperty)
可能的重复