小编use*_*622的帖子

使用jquery ajax提交表单

我正在尝试学习MVC,我想要做的事情是将表单提交给我的控制器中的操作,此操作将返回提交的数据.听起来很简单,但我已经尝试了几个小时而没有任何成功.我的看法:

 @using (Html.BeginForm("BlogComment","Blog"))
 {
     @Html.ValidationSummary(true)
    <legend class="AddAComment">Add a comment</legend>

    <div class="commentformwrapper">

        <div class="editor-text">
        <span class="editor-label">User Name:</span>
        </div>

        <div class="editor-text">
        <input type="text" id="username" />
        </div>

        <div class="editor-text">
        <textarea id="comment" rows="6" cols="23"></textarea>
        </div>

        <div class="editor-field">
        <input type="hidden" id="hiddendate" />
        </div>

        <input type="submit" id="submit" value="Create" />

    </div>
}
Run Code Online (Sandbox Code Playgroud)

我的控制器:

[HttpPost]   
public ActionResult CommentForm(Comment comment)
{
    Comment ajaxComment = new Comment();
    ajaxComment.CommentText = comment.UserName;
    ajaxComment.DateCreated = comment.DateCreated;
    ajaxComment.PostId = comment.PostId;
    ajaxComment.UserName = comment.UserName;

    mRep.Add(ajaxComment);
    uow.Save();
    //Get all the comments for the given post id …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc jquery

15
推荐指数
3
解决办法
7万
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

jquery ×1