【发布时间】:2016-11-04 02:35:29
【问题描述】:
我有一个与两个模型绑定的视图...所以我选择ViewModel 方法将两个模型与一个视图绑定...但是我在创建Create 类型的视图时遇到了问题...但是我我面临错误...FeedbackMix 在这里是 ViewModel...我必须传递查询对象以在布局中显示某些内容,同时我必须创建类型视图页面...
错误:强>
CS1061:“FeedbackMixModel”不包含“Message”的定义,并且找不到接受“FeedbackMixModel”类型的第一个参数的扩展方法“Message”(您是否缺少 using 指令或程序集引用?)
控制器
public ActionResult Create()
{
var msg= db.Messages.ToList();
var feed = db.Feedbacks.ToList();
FeedbackMixModel vm = new FeedbackMixModel();
vm.allfeedbacks = feed;
//this is also create type view
return View(vm);
}
查看
@model WebApplication5.Models.FeedbackMixModel
....
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
....
@Html.LabelFor(model => model.Message, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Message, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Message, "", new { @class = "text-danger" })
</div>
....
}
视图模型
public class FeedbackMixModel
{
public List<UserManager> allUserManagers { get; set; }
public List<Feedback> allfeedbacks { get; set; }
public List<Package> allpackages { get; set; }
public List<Messages> allmessages { get; set; }
}
错误行
第 16 行:@Html.LabelFor(model => model.Message, htmlAttributes: new { @class= "control-label col-md-2" })
【问题讨论】:
-
错误信息非常简单...在您的
FeedbackMixModel中您没有Message属性或方法 -
是的,我知道我粘贴了这段代码,这样你们就可以轻松理解了场景。
标签: c# asp.net-mvc