我的MVC5视图在渲染时抛出错误。我不确定为什么,或者如何跟踪它。
错误是:
无法转换类型为&System; Guid'的对象。输入' System.String'。
razer是:
<div class="form-group">
@Html.LabelFor(model => model.LogoUrl, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LogoUrl, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LogoUrl, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FullTimeEnrollment, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FullTimeEnrollment, new { htmlAttributes = new { @class = "form-control" } })
@* This next line errors, not sure why *@
@Html.ValidationMessageFor(model => model.FullTimeEnrollment, "", new { @class = "text-danger" })
</div>
</div>
模型的定义如下:
public class Organization : BaseEntity, IAuditableEntity
{
//...
[Display(Name = "FullTime Enrollment")]
public string FullTimeEnrollment { get; set; }
//...
}
我的控制器正在加载视图:
public ActionResult organizationdetails(Guid? id)
{
if (!IsAuthenticated("You must be logged in to access this page.", string.Empty))
{
return RedirectToAction("Index", "Submission", new { returnUrl = Request.Url.AbsolutePath });
}
ViewData["OrgId"] = id;
ViewBag.Title = id == Guid.Empty ? "Create Organization" : "Edit Organization";
var org = db.Organization.Find(id);
ViewBag.OrganizationTypes = Lookups.GetCached(CachedLists.OrganizationTypes) as List<OrganizationType>;
return View(org);
}
错误发生在&#39; @ Html.ValidationMessageFor(model =&gt; model.FullTimeEnrollment&#39;。当我检查控制器时,模型看起来很好.FullTimeEnrollment为空。
如何调试此类问题?