@foreach(在Model.Comments.Where VAR commentlist(X => x.CommentParentID == 0)){ @ Html.Hidden get和設定值剃刀MVC 4
<div class="blog-comment">
<div class="comment-info">
<div class="user-info">
@if (commentlist.AllowViewingProfiles)
{
<a href="@Url.RouteUrl("CustomerProfile", new { id = commentlist.CustomerId })" class="username">@(commentlist.CustomerName)</a>
}
else
{
<span class="username">@(commentlist.CustomerName)</span>
}
<div class="avatar">
@if (!String.IsNullOrEmpty(commentlist.CustomerAvatarUrl))
{
<img src="@(commentlist.CustomerAvatarUrl)" class="avatar-img" title="avatar" alt="avatar" />
}
</div>
</div>
</div>
<div class="comment-content">
<div class="comment-time">
@T("Blog.Comments.CreatedOn"): <span class="stat-value">@commentlist.CreatedOn.ToString("g")</span>
<div class="buttons">
<input type="submit" id="reply" class="button-1 blog-post-add-comment-button" onclick="return showHide();" />
@Html.Hidden("CommentParentID",@commentlist.Id)
</div>
</div>
<div class="comment-body">
@Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(commentlist.CommentText, false, true, false, false, false, false))
</div>
</div>
<div class="clear">
</div>
}
我使用@ Html.Hidden(「CommentParentID」,@ commentlist.Id)爲ChildComment設置值CommentParentID(如果有的話)。
在下面的操作我想通過CommentParentID作爲參數。
@Html.ActionLink("Reply", "BlogCommentReply", "Blog", new { blogPostId = blogPostId, CommentParentID=CommentParentID,captchaValid = Model.AddNewComment.DisplayCaptcha }, null)
我如何檢索控制器中隱藏的字段值? 或我如何傳遞這個值?
。 – NetraSW
表格怎麼樣?看起來你的HTML頁面沒有形式。請注意,如果不使用Ajax提交表單或發佈信息,則無法將字段值從頁面傳遞到控制器。 –