部分视图验证 [英] Validation on partial view
问题描述
嗨
我有一个带有表单的局部视图,当我点击提交按钮时,没有验证错误消息。
这就是我所拥有的:
@using(Html.BeginForm( GetPartialView, 管理,FormMethod .Post, new {enctype = multipart / form- data,id = LoginForm}))
{
@ Html.AntiForgeryToken()
< div class = form-group >
@ Html.LabelFor(model = > model.Isbn)
@ Html.EditorFor(model = > model.Isbn, new {htmlAttributes = new {@class = 表单-control}})
< button id = loginButton class = btn btn-common-小类型= 按钮> Opret < / 按钮 >
}
我尝试了什么:
我试过这个jquey。
jQuery(document).ready(function($){
$('#loginButton')。click(function(function) ){
$ .ajax({
类型:POST,
url:'@ Url .Action(GetPartialView,Manage)',
数据:$('form')。serialize(),
成功:函数(结果){
var form = $('#LoginForm');
if(result.redirectTo){
window.location.href = result.redirectTo ;
} else {
$(#LoginFormContainer)。html(result);
form.data('validator',null );
$ .validator.unobtrusive.parse(form);
}
},
错误: function(){
$(#LoginForm)。html(result);
}
});
});
});
但这只有在我将按钮类型从提交更改为按钮时才有效,但我的文件上载不起作用。
/ Tina
){
< blockquote>('#loginButton')。click(function(){
.ajax({
键入:POST,
url:'@ Url.Action(GetPartialView,Manage)',
data:
Hi
I have a partial view with a form, when I am clicked on the submit button there is no validation error message.
This is what I have:
@using (Html.BeginForm("GetPartialView", "Manage", FormMethod.Post, new { enctype="multipart/form-data", id = "LoginForm" }))
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.LabelFor(model => model.Isbn)
@Html.EditorFor(model => model.Isbn, new { htmlAttributes = new { @class = "form-control" } })
<button id="loginButton" class="btn btn-common-small" type="button">Opret</button>
}
What I have tried:
I have tried this jquey.
jQuery(document).ready(function ($) {
$('#loginButton').click(function () {
$.ajax({
type: "POST",
url: '@Url.Action("GetPartialView", "Manage")',
data: $('form').serialize(),
success: function (result) {
var form = $('#LoginForm');
if (result.redirectTo) {
window.location.href = result.redirectTo;
} else {
$("#LoginFormContainer").html(result);
form.data('validator', null);
$.validator.unobtrusive.parse(form);
}
},
error: function () {
$("#LoginForm").html(result);
}
});
});
});
But this is only work if I change the button type from submit to button, but then my fileupload wont work.
/Tina
) {
('#loginButton').click(function () {
.ajax({
type: "POST",
url: '@Url.Action("GetPartialView", "Manage")',
data:
这篇关于部分视图验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!