【问题标题】:how to set model parameter value in view如何在视图中设置模型参数值
【发布时间】:2013-01-07 12:23:18
【问题描述】:
<div class="forms-box">
   <div class="inputs">
       @Html.HiddenFor(model => model.AddNewComment.CommentParentID)
       @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>

在代码中:

我从两个中得到一个值

  1. Model.AddNewComment.CommentParentID 或

  2. Model.AddNewComment.CommentText

在我的控制器中。

  public ActionResult BlogCommentReply(
         int blogPostId,
         BlogPostModel model, 
         bool captchaValid)
 {

 }

【问题讨论】:

  • 你能分享你的 BlogPostModel 代码吗?另外,您是发布到 HttpPost 操作还是通用 GET/POST 操作?

标签: c#-4.0 razor asp.net-mvc-4


【解决方案1】:

解决方案: model.AddNewComment.CommentText 字段是强制性的。 所以我只是做了以下事情。

 @using (Html.BeginForm())
                        {
                            <div id="div_@Count" style="display: none;">
                                @{CommentParentID = comment.Id;
                                  Model.AddNewComment.CommentParentID = CommentParentID;
                                  Model.AddNewComment.CommentText = comment.CommentText;}
                                <div id="ChildComments">
                                    @Html.HiddenFor(model => model.AddNewComment.CommentParentID)
                                    @Html.Label("Reply Comment")
                                    <div>
                                        @Html.TextAreaFor(model => model.AddNewComment.ChildCommentText)
                                    </div>
                                    @Html.HiddenFor(model => model.AddNewComment.CommentText)
                                </div>
                                <div class="buttons">
                                    <input type="submit" name="reply-comment"  value="@T("Blog.Comments.ReplyButton")" />
                                </div>
                            </div>



                        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多