剃刀视图未显示导航属性值

时间:2012-03-04 17:13:38

标签: asp.net-mvc-3 razor

我有以下行动方法: -

[HttpPost]
        public ActionResult Create(int questionid, Answer a)
        {
            if (ModelState.IsValid)
            {
        repository.AddAnswer(a);
             repository.Save();
             return PartialView("_details",a);
            }
            return View(a);

以及下面的详细信息: -

    <td>
        @Html.DisplayFor(modelItem => Model.Description)
    </td>
    <td>
        @Html.DisplayFor(modelItem => Model.Answer_Description.description)
    </td>
    <td>
     @Ajax.ActionLink("Delete", "Delete", "Answer",
    new { id = Model.AnswersID },
      new AjaxOptions
      {
          Confirm = "Are You sure You want to delete this Answer ?",
          HttpMethod = "Post",
          UpdateTargetId = Model.AnswersID.ToString()
                    })


    </td>
    </tr>

我面临的问题是,在调用ajx后,@Html.DisplayFor(modelItem => Model.Answer_Description.description)值不会自动显示,除非我刷新网页。那么可能是什么问题? < / p>

1 个答案:

答案 0 :(得分:0)

我怀疑是否存在延迟加载问题(很难确定您提供的信息,但是)...

由于Model.Description似乎是一个原始(字符串)属性,但Answer_Description.description是导航属性的原始属性。

您确定Answer_Description已正确加载吗?

编辑:更精确一点:您的操作收到答案:传递后是否有Answer_Description.description? 如果不是,您应该在返回View ...

之前从数据库中获取Answer_Description