首页 新闻 赞助 找找看

MVC,无刷新

0
悬赏园豆:15 [已关闭问题] 关闭于 2013-08-01 14:45

<!--评论内容开始------------------>
             
           <p class="xinwenplp">發表評論</p>
             <!-- 评论底部开始-->
                 <div class="xszbr_bot" style="background:none;">
                
                 <!--表情------------------->
                    <div class="xszbrb_biaoqing xinwenbq">
                       <a href='javascript:InsertImage("[微笑]")'><img src="@Url.Content("~/Content/ubb/1.jpg")"/></a>
                        <a href='javascript:InsertImage("[惊恐]")'><img src="@Url.Content("~/Content/ubb/2.jpg")"/></a>
                   <!--class="xszbrb_biaoqing xinwenbq" end--> </div>
                  <!--表情----------------->
                 
                  <!--暱稱-----------------> 
          @using (Html.BeginForm("Post", "Vedio"))
        {
            @Html.ValidationSummary(true)
            <fieldset>
                <div class="xszbrb_nicheng">
                    <span class="xszbrb_ncspan">暱 稱:</span>
                    @Html.TextBoxFor(model => model.UserName, new { @class = "xszbrb_nciput" })
                    @Html.ValidationMessageFor(model => model.UserName)
                </div>
                <div class="xszbrb_wduohang">
                    @Html.TextAreaFor(model => model.Content, new { @class = "xszbrb_duohang", row = "4", cols = "25" })
                </div>
                <!-- 验证码回复第一行-->
                <div class="xszbrb_yanzhmtu" style="width: 640px;">
                <span id="vcode_error" style="color:Red"></span>
                    @Html.ValidationMessageFor(model => model.Vcode)
                    @Html.ValidationMessageFor(model => model.Content)
                </div>
                <!-- 验证码回复第一行-->
                <!-- 红色提示 -->
                <div class="xszbrb_yanzhm">
                    <span class="xszbrb_ncspan">請輸入驗證碼:</span> <span class="xszbrb_yziputw">
                        @Html.TextBoxFor(model => model.Vcode, new { @calss = "xszbrb_yziput", width = "80px" })
                    </span>
                    <img src="/VerificationCode/Show" id="NumberPicture" align="absmiddle" style="border: 0px;
                        cursor: pointer" title='如果您无法识别验证码,点击图片更换' onclick="javascript:this.src='/VerificationCode/Show?r='+Math.random()" />

                        @Html.HiddenFor(model => model.ForwardId)
                        @Html.HiddenFor(model => model.Type)
                        @Html.HiddenFor(model => model.ObjectId)
                 
                        <input name="time" value="提交" type="submit" id="submit" class="xszbrb_sub" style="border: none;" />
              
                </div>
            </fieldset>

        }
                         <!--评论-->
                        <div class="xszbrb_pltt xinwenplj">
                            <span>little_tutu</span>
                            :這個視頻真好看,是我喜歡的類型。這個視頻真好看,是我喜歡的類型。這個視頻真視頻歡的類型。類型。這個視頻真好看,是我喜歡的類型。這個視頻真視頻歡的類型,類型這個視頻真視頻歡的類型。
                            <div class="xinwenplz">5月9日 12:22</div>
                       <!--class="xszbrb_pltt xinwenplj" end--> </div>
                         <!--评论-->
                        
                    <!-- page+共两条 -->    
                    <div class="xszbrb_pingluno zcrdnc">
                                <p class="xszb_plg">共 @ViewData["num"]条</p>
                               <div class="pages" style="float:right;margin-top:3px;">
                                <div id="Pagination"></div>
                               </div>
                            
                             </div>
                    <!-- page+共两条 -->
                   
                <!--class="xszbr_bot" end--> </div>
             <!-- 评论底部结束-->
        <!--评论内容结束------------------>
    <!--class="newsc_left" end--> </div>

 

 

 [HttpPost]
        public ActionResult Post(PostCommentModel model)
        {

            if (ModelState.IsValid)
            {
                model.IsAnonymous = SiteSettings.Instance.IsAnonymous;
                if (model.IsAnonymous == 0)
                {
                    model.UserId = 0;
                }
                model.UserIp = Tools.IpToInt();
                var ret = VerificationCodeManager.Validate(model.Vcode);
                if (ret != ValidateMessage.Ok)
                {
                    return Json(new { error = "1" });
                }
                model.CreatedTime = DateTime.Now;

                int conmmentId = CommentDAL.AddComment(model);
                if (conmmentId > 1)
                {
                    GetCommentModel comment = CommentDAL.GetComment(conmmentId);
                    comment.Content = Tools.Ubb(comment.Content);
                    JsonResult json = new JsonResult();
                    json.Data = comment;
                    return json;
                }
                return Json(new { error = "" });
            }
            else
            {
                return Json(new { error = "0" });
            }

        }

        public JsonResult Get(int objectId,int pageIndex,int pageSize,int type)
        {
            int page = 1;
            int size = 10;
            int id = 0;
            int typeId = 0;
            if (Request["objectId"] != null)
            {
                if (!int.TryParse(Request["objectId"], out id))
                {
                    id = 1;
                }
            }
            if (Request["pageIndex"] != null)
            {
                if (!int.TryParse(Request["pageIndex"], out page))
                {
                    page = 1;
                }
            }
            if (Request["pageSize"] != null)
            {
                if (!int.TryParse(Request["pageSize"], out size))
                {
                    size = 10;
                }
            }
            if (Request["type"] != null)
            {
                if (!int.TryParse(Request["type"], out typeId))
                {
                    typeId = 0;
                }
            }

            var model = CommentDAL.GetComment(size, page, id,typeId);
            foreach (var comment in model)
            {
                comment.Content = Tools.Ubb(comment.Content);
            }
            JsonResult json = new JsonResult();
            json.Data = model.ToList();

            return json;
        }

 我想问下为什么它总是执行   return Json(new { error = "0" }); ,我想知道那里错啦?

不能添加,因为我刚接触这个,是在别人的基础上做的,他人不在啦,所以想问下,谁知道谢谢大家啦。

萧布衣的主页 萧布衣 | 初学一级 | 园豆:77
提问于:2012-06-28 19:11
< >
分享
所有回答(1)
0

ModelState.IsValid 是false,驗證 沒有通過。

無限遐想 | 园豆:3740 (老鸟四级) | 2012-06-29 13:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册