我有一個觀點,我想在線程和註釋中這樣做,當我執行該帖子時,它將具有並且能夠更新兩者。將多個值傳遞到視圖中
這裏是視圖:
@model GameDiscussionBazzar.Data.Comment
@{
ViewBag.Title = "EditComment";
Layout = "~/Views/Shared/_EditCommentLayout.cshtml";
}
<div class="EditComment">
<h1>
Edit Comment
</h1>
@using (Html.BeginForm("EditThreadComment", "Comment"))
{
<div class="EditingComment">
@Html.EditorForModel()
@Html.Hidden("comment", Model)
@Html.HiddenFor(i => i.ParentThread)
<input type="submit" value="Save"/>
@Html.ActionLink("Return without saving", "Index")
</div>
}
</div>
我有2種方法之一就是動作結果的同時,另一種是返回到主頁,如果它succeded後返回視圖。 這裏的方法:
public ActionResult EditThreadComment(int commentId)
{
Comment comment = _repository.Comments.FirstOrDefault(c => c.Id == commentId);
return View(comment);
}
[HttpPost]
public ActionResult EditThreadComment(Comment comment, Thread thread)
{
var c = thread.ChildComments.FirstOrDefault(x => x.Id == comment.Id);
thread.ChildComments.Remove(c);
if (ModelState.IsValid)
{
_repository.SaveComment(comment);
thread.ChildComments.Add(comment);
_tRepo.SaveThread(thread);
TempData["Message"] = "Your comment has been saved";
return RedirectToAction("Index", "Thread");
}
else
{
TempData["Message"] = "Your comment has not been saved";
return RedirectToAction("Index", "Thread");
}
}
如此反覆,我的問題是我如何通過2個參數到視圖?或者我如何傳遞線程的值?