加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – asp.net mvc3 jquery ui对话框和客户端验证

发布时间:2020-12-15 19:03:38 所属栏目:asp.Net 来源:网络整理
导读:我在asp.net mvc3应用程序中有客户端验证问题. 我的代码看起来 function loadEditCategoryDialog(categoryId) { $.ajax({ url : "/rovastamp3/Admin/CategoryEditDialog",data : "categoryId="+categoryId,success : function(data){ $("#popup_dialog").htm
我在asp.net mvc3应用程序中有客户端验证问题.

我的代码看起来

function loadEditCategoryDialog(categoryId) {
    $.ajax({
        url : "/rovastamp3/Admin/CategoryEditDialog",data : "categoryId="+categoryId,success : function(data){
            $("#popup_dialog").html(data);
            $("#popup_dialog").dialog({        
                modal: true,draggable: false,resizable: false,title: "Upravit kategorii",width: 600,height: 500,});                             
        }
    });
 }

控制器:

[HttpGet]
public ActionResult CategoryEditDialog(int categoryId)
{
    CategoryEditViewModel categoryEditViewModel = new CategoryEditViewModel();
    categoryEditViewModel.Category = _postAuctionCategoryRepo.Query()
        .SingleOrDefault(x => x.Id == categoryId);

    return PartialView(categoryEditViewModel);
}

[HttpPost]
public ActionResult CreateNewCategory(CategoryEditViewModel categoryEditViewModel)
{
    if (ModelState.IsValid)
    {
        return RedirectToAction("Index");
    }
    return View("CategoryEditDialog",categoryEditViewModel);
}

最后我的部分看法:

@model Rovastamp.MVC3.ViewModels.AdminController.CategoryEditViewModel
<h2>Upravit kategorii @Model.Category.Name</h2>
@{Html.EnableClientValidation();}
@using (Html.BeginForm("CreateNewCategory","Admin"))
{ 
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Objednávkovy formulá?</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Category.Name) 
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Category.Name) 
            @Html.ValidationMessageFor(model => model.Category.Name) 
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Category.Position) 
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Category.Position) 
            @Html.ValidationMessageFor(model => model.Category.Position) 
        </div>

        <input  type="submit" value="Upravit" class="submit_button" />               
    </fieldset>
}

在我的web.config中,我打开了UnobtrusiveJavaScript和ClientValidatin应用程序设置.

如果我在jquery ui对话框上提交按钮,mvc在没有客户端验证的情况下完全刷新?

哪里有问题?

感谢任何帮助

编辑:

在我的布局页面中,我包括这个脚本:

> jquery.unobtrusive-ajax.js
> jquery.validate.js
> jquery.validate.unobtrusive.js

编辑2

在我的exemaple我放:

jQuery.validator.unobtrusive.parse('#popup_dialog');

之前我调用jquery ui对话框和客户端验证工作完美.

解决方法

这是因为您正在将PartialView加载到已由jquery.validator.unobstrusive库解析的View中.您需要指示库重新解析页面以考虑您注入的PartialView验证属性.阅读我的 this blog post的这个话题,希望能回答你的问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读