将[{1}}与$("#formtest").valid()
一起使用时,false
总是enum
,我遇到了问题。
如果我删除RadioButtonFor
RadioButtonFor
现在是$("#formtest").valid()
。
有人可以建议如何解决这个问题吗?
我的设置:
true
)通过jQuery ajax处理POST 这是我的代码:
TestSurfaceController.cs
Test.cshtml:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/scripts/jquery.validate.js"></script>
<script src="/scripts/jquery.validate.unobtrusive.js"></script>
Test.cshtml使用TestViewModel.cs:
@using MyProject_Umbraco.Models
@inherits UmbracoViewPage<MyProject_Umbraco.Models.TestViewModel>
@{
Layout = "Layout.cshtml";
}
@using (Html.BeginForm(null, null, FormMethod.Post, new {id = "formtest"}))
{
@Html.TextBoxFor(m => m.Model.FullName)
<ul>
<li>@Html.RadioButtonFor(m => m.Model.NotificationsFrequency, NotificationsFrequency.Instantly) Instant</li>
<li>@Html.RadioButtonFor(m => m.Model.NotificationsFrequency, NotificationsFrequency.Daily) Daily</li>
</ul>
<a id="btnSignup">Sign up</a>
}
@section BottomScripts
{
<script>
$(function() {
$("#btnSignup").on("click", function() {
signup();
});
var signup = function() {
$("#formtest").validate();
if ($("#formtest").valid()) { // always false
var obj = $("#formtest").serializeArray();
$.ajax({
url: "@Url.Action("Index", "TestSurface")",
type: "POST",
data: obj,
success: function(result) {
alert(result);
}
});
} // end if valid()
}; // end signup()
});
</script>
}
TestDataModel.cs
using System.Globalization;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
namespace MyProject_Umbraco.Models
{
public class TestViewModel : RenderModel
{
public TestViewModel(IPublishedContent content, CultureInfo culture)
: base(content, culture)
{
Model = new TestDataModel();
}
public TestViewModel(IPublishedContent content)
: base(content)
{
Model = new TestDataModel();
}
public TestDataModel Model { get; set; }
}
}
NotificationsFrequency.cs
namespace MyProject_Umbraco.Models
{
public class TestDataModel
{
public string FullName { get; set; }
public NotificationsFrequency NotificationsFrequency { get; set; }
}
}
呈现的HTML:
public enum NotificationsFrequency
{
Instantly = 1,
Daily = 2
}
答案 0 :(得分:0)
管理来解决这个问题。
事实证明,存在一些冲突的javascript库。通过将库更新为最新版本来修复。