我会用在很多不同的页面,这将是不同的仅仅是参考模型(@model ...)相同的部分错误。我试着用“@model动态”这样我就可以在观看基准模型,但是lambda表达式是在我的部分被引用特定属性都扔了以下错误:使用使用剃刀语法谐音动态模型抛出
"An expression tree may not contain a dynamic operation"
caused by the following reference to model:
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
如何构建我的代码或创建一个模型引用将动态工作,以便我可以在我的视图页面中引用每个特定的模型实例?我在网上尝试了很多解决方案,到目前为止没有任何工作。以下是我的部分观点。任何帮助将不胜感激!!!
部分:
@model dynamic
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="container creative-containter-top">
<div class="row">
<div class="col-sm-offset-2 col-sm-8">
<div class="form-horizontal">
<div class="panel panel-primary">
<div class="panel-height pane panel-heading text-center">
<h3>@ViewBag.Title</h3>
</div>
<div class="panel-body">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Code, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Code, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Code, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Code, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Code, new { htmlAttributes = new { @class = "checkbox center-block" } })
@Html.ValidationMessageFor(model => model.Code, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</div>
</div>
<div class="panel-footer">
@Html.ActionLink("Back to List", "Index")
</div>
</div>
</div>
</div>
</div>
</div>
}
查看
@model CreativeNamingConvention.Models.Domain.CreativeOps
@{
ViewBag.Model = Model;
ViewBag.Title = "Edit Creative Ops Field";
}
@Html.Partial("~/Views/Templates/editBody.cshtml", Model)
为什么你使用'dynamic'反正?所有模型都有一个你想访问的特定属性吗?然后让他们实现一个接口,然后使用强类型化到该接口的模型。 – mason
动态是一个非常糟糕的方式来使用asp.net-mvc。 –