如何实现MVC ActionResult 返回类型为JavaScriptResult

必需的js引用文件

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
@Scripts.Render("~/bundles/jquery")

 

View页面

  @using (Ajax.BeginForm("EditGPY", "GPY", new AjaxOptions(), new { @id = "frmgpy", @class = "form-horizontal" }))
                        {
                            @Html.HiddenFor(m => m.PicPath)
                            <table>
                                <tr><td>保存路径</td><td style="padding-left:1em">@Html.TextBoxFor(m => m.SavePath, new { @class = "form-control", @id = "FilePath", @readonly = "readonly" })</td></tr>
                            </table>
                            <div class="form-group">
                                <div class="col-md-10">
                                    @Html.HiddenFor(m => m.ReceiptNo, new { @id = "txtReceiptNo" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-2 col-md-10">
                                    <input data-ajax="true" type="submit" class="btn btn-primary" value="上传文件" />
                                </div>
                            </div>
                        }

 

Controller

if (string.IsNullOrEmpty(model.ReceiptNo) || string.IsNullOrEmpty(model.SavePath) || string.IsNullOrEmpty(model.PicPath))
{
  return base.JavaScript("alert('信息有误,不能上传')");
}

效果

 

posted on 2016-08-22 09:30  码农老K  阅读(1243)  评论(0)    收藏  举报

导航