C# 我们可以在单视图中使用多个html.begin吗?
我正在写博客帖子嵌套评论 我已经习惯了html.beginform,一个用于添加新评论,另一个用于回复 我的看法是:C# 我们可以在单视图中使用多个html.begin吗?,c#,razor,asp.net-mvc-4,C#,Razor,Asp.net Mvc 4,我正在写博客帖子嵌套评论 我已经习惯了html.beginform,一个用于添加新评论,另一个用于回复 我的看法是: <fieldset class="new-comment"> <legend class="title">@T("Blog.Comments.LeaveYourComment")</legend> @using (Html.BeginForm()) {
<fieldset class="new-comment">
<legend class="title">@T("Blog.Comments.LeaveYourComment")</legend>
@using (Html.BeginForm())
{
<div id="newcomment">
<div class="message-error">@Html.ValidationSummary(true)</div>
@{
string result = TempData["nop.blog.addcomment.result"] as string;
}
@if (!String.IsNullOrEmpty(result))
{
<div class="result">@result</div>
}
<div class="forms-box">
<div class="inputs">
@Html.LabelFor(model => model.AddNewComment.CommentText)
<div class="input-box">
@Html.TextAreaFor(model => model.AddNewComment.CommentText, new { @class = "comment-text" })
</div>
@Html.ValidationMessageFor(model => model.AddNewComment.CommentText)
</div>
@if (Model.AddNewComment.DisplayCaptcha)
{
<div class="captcha-box">
@Html.Raw(Html.GenerateCaptcha())
</div>
<div class="clear">
</div>
}
</div>
<div class="clear">
</div>
<div class="buttons">
<input type="submit" name="add-comment" class="button-1 blog-post-add-comment-button" value="@T("Blog.Comments.SubmitButton")" />
</div>
</div>
}
</fieldset>
@T(“Blog.Comments.LeaveYourComment”)
@使用(Html.BeginForm())
{
@Html.ValidationSummary(true)
@{
string result=TempData[“nop.blog.addcomment.result”]作为字符串;
}
@如果(!String.IsNullOrEmpty(结果))
{
@结果
}
@LabelFor(model=>model.AddNewComment.CommentText)
@Html.TextAreaFor(model=>model.AddNewComment.CommentText,new{@class=“comment text”})
@Html.ValidationMessageFor(model=>model.AddNewComment.CommentText)
@if(Model.AddNewComment.DisplayCaptcha)
{
@Html.Raw(Html.GenerateCaptcha())
}
}
答复:
<div class="container">
@{//to set div id in comment list
var Count = 0;
var CommentParentID = 0; }
@using (Html.BeginForm())
{
foreach (var commentlist in Model.Comments.Where(x => x.CommentParentID == 0))
{
<div class="nested-comments">
<div>
@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 class="comment-content">
<div class="comment-time">
@T("Blog.Comments.CreatedOn"): <span class="stat-value">@commentlist.CreatedOn.ToString("g")</span>
<div>
<div id="div_@Count" style="display: none;">
@{CommentParentID = commentlist.Id;
Model.AddNewComment.CommentParentID = CommentParentID;}
<div>
<div class="message-error">@Html.ValidationSummary(true)</div>
@{
string strresult = TempData["nop.blog.addcomment.result"] as string;
}
@if (!String.IsNullOrEmpty(strresult))
{
<div class="result">@strresult</div>
}
<div>
<div id="ChildComment_@Model.AddNewComment.CommentParentID">
@Html.HiddenFor(modelComment => modelComment.AddNewComment.CommentParentID)
@Html.Label("Reply Comment")
<div>
@Html.TextAreaFor(modelComment => modelComment.AddNewComment.ChildCommentText)
</div>
@Html.ValidationMessageFor(modelComment => modelComment.AddNewComment.ChildCommentText,"Please Enter Reply")
</div>
@if (Model.AddNewComment.DisplayCaptcha)
{
<div class="captcha-box">
@Html.Raw(Html.GenerateCaptcha())
</div>
<div class="clear">
</div>
}
</div>
<div class="clear">
</div>
<div class="buttons">
<input type="submit" name="reply-comment" value="@T("Blog.Comments.ReplyButton")" />
</div>
</div>
<div class="clear">
</div>
</div>
<input type="button" id="reply" class="reply-link" onclick="return showHide('div_@Count');" value="Reply" />
@{Count++; }
</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>
@foreach (var cmt in Model.Comments.Where(x => x.CommentParentID == commentlist.Id))
{
<div class="comment">
<div>
<div class="user-info">
@if (cmt.AllowViewingProfiles)
{
<a href="@Url.RouteUrl("CustomerProfile", new { id = cmt.CustomerId })" class="username">@(cmt.CustomerName)</a>
}
else
{
<span class="username">@(cmt.CustomerName)</span>
}
<div class="avatar">
@if (!String.IsNullOrEmpty(cmt.CustomerAvatarUrl))
{
<img src="@(cmt.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">@cmt.CreatedOn.ToString("g")</span>
</div>
<div class="comment-body">
@Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(cmt.CommentText, false, true, false, false, false, false))
</div>
</div>
</div>
}
@Html.Widget("blogpost_page_inside_comment")
</div>
</div>
}
}
</div>
@{//在注释列表中设置div id
var计数=0;
var CommentParentID=0;}
@使用(Html.BeginForm())
{
foreach(Model.Comments.Where(x=>x.CommentParentID==0)中的var commentlist)
{
@if(commentlist.AllowViewingProfiles)
{
}
其他的
{
@(commentlist.CustomerName)
}
@如果(!String.IsNullOrEmpty(commentlist.CustomerAvataUrl))
{
}
@T(“Blog.Comments.CreatedOn”):@commentlist.CreatedOn.ToString(“g”)
@{CommentParentID=commentlist.Id;
Model.AddNewComment.CommentParentID=CommentParentID;}
@Html.ValidationSummary(true)
@{
字符串strresult=TempData[“nop.blog.addcomment.result”]作为字符串;
}
@如果(!String.IsNullOrEmpty(strresult))
{
@strresult
}
@Html.HiddenFor(modelcoment=>modelcoment.AddNewComment.CommentParentID)
@Html.Label(“回复注释”)
@TextAreaFor(modelComment=>modelComment.AddNewComment.ChildCommentText)
@Html.ValidationMessageFor(modelcoment=>modelcoment.AddNewComment.ChildCommentText,“请输入回复”)
@if(Model.AddNewComment.DisplayCaptcha)
{
@Html.Raw(Html.GenerateCaptcha())
}
@{Count++;}
@Html.Raw(Nop.Core.Html.HtmlHelper.FormatText(commentlist.CommentText,false,true,false,false))
@弗雷奇