我试图使用条件语句KnockoutValidation.见下面的代码:
self.transactionType = ko.observable('Option1');
self.ConditionalField = ko.observable().extend({
required: true,
onlyIf: self.transactionType = ="Option2"
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.我想要ConditionalField只有transactionType有价值的要求'Option2'.
使用knockout.validation.js进行条件验证的最佳方法是什么?
我对这个问题感到不满.我确实在互联网上找到了一些关于它的内容,但不是一个明确的答案.我的问题:
我必须在MVC3 Web应用程序的Model部分中的类:ParentClass和ChildClass在ParentClass上有一个属性子类型List
我使用了EF Code First,它在数据库中为我整齐地生成了父表和子表.
现在我需要一个REST服务,它返回一个List或一个ParentClass.
当我从ParentClass中删除属性Children时没有问题.但随着孩子们的到来,我不断收到错误.
错误: "The type System.Data.Entity.DynamicProxies.ParentClass_A0EBE0D1022D01EB84B81873D49DEECC60879FC4152BB115215C3EC16FB8003A was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}
一些代码:
类别:
public class ParentClass
{
public int ID { get; set; }
public string Name {get;set;}
public virtual List<ChildrenClass> Children { get; set; }
}
public class ChildrenClass
{
public int ID { get; set; }
public string MyProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
服务:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(IncludeExceptionDetailInFaults …Run Code Online (Sandbox Code Playgroud) rest entity-framework ef-code-first asp.net-mvc-3 wcf-web-api
请考虑以下情形.
文档 - >部分 - >正文 - >项目
文档有部分,一个部分包含一个正文.正文包含一些文本和项目列表.这些项目就是问题所在.有时这些项是字符串的基本列表,但有时这些项包含自定义数据类型的列表.
所以:
public class Document
{
public Section[] Sections{get;set;}
}
public class Section
{
public SectionType Type{get;set;}
public Body {get;set;}
}
public class Body
{
//I want the items to be depending on the section type.
//If e.g. the sectiontype is experience, I want the Items to be created with type //Experience. If sectiontype is default I want the Items to be created with type string
public Items<T> Items {get;set;}
}
public …Run Code Online (Sandbox Code Playgroud) 有没有办法在时间线视图中隐藏时间.在月份时间线中,您只能看到日期,没有时间,但在周时间线中,也会显示时间.
我希望它在周时间线中是相同的.我需要这个,因为我的所有活动都是全天活动,所以不需要显示时间轴.
期望的结果:
资源| 周一1/12 | 星期二2月12日 3月3日星期三| 星期四4/12 | 5月5日星期五| 星期六6月12日 太阳7/12
我正在尝试实现Asp.Net Identity 2.0.到目前为止,我已经在这个博客的帮助下做得很好.但是我的道路略有不同.我希望一些数据不是User对象的一部分,而是一个新创建的Customer对象.我希望将身份验证和授权数据与我的业务数据分开.
所以在我的例子中,我通过添加一个客户属性修改了ApplicationUser类:
public Customer Customer { get; set; }
Run Code Online (Sandbox Code Playgroud)
Customer类看起来像这样:
public class Customer
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Insertion { get; set; }
public Gender Gender { get; set; }
public DateTime Birthdate { get; set; }
...etc.
public virtual ApplicationUser User { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我还在ApplicationDbContext中添加了关系:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Customer>()
.HasRequired(u => …Run Code Online (Sandbox Code Playgroud) 我已经设法根据Niemeyer给出的答案创建了一个简单的向导.这很好用.我想添加验证.我已设法在字段名称上添加必需的验证.保留此空显示错误.但我无法成功的是:在当前步骤中验证模型,并根据是否存在错误启用或禁用下一步.如果启用或禁用下一个按钮太困难,那就没问题.当出现错误时,我也可以在没有禁用按钮的情况下生活.只要在出现错误时阻止用户进入下一步骤.
.我的观点如下:
//model is retrieved from server model
<script type="text/javascript">
var serverViewModel = @Html.Raw(Json.Encode(Model));
</script>
<h2>Test with wizard using Knockout.js</h2>
<div data-bind="template: { name: 'currentTmpl', data: currentStep }"></div>
<hr/>
<button data-bind="click: goPrevious, enable: canGoPrevious">Previous</button>
<button data-bind="click: goNext, enable: canGoNext">Next</button>
<script id="currentTmpl" type="text/html">
<h2 data-bind="text: name"></h2>
<div data-bind="template: { name: getTemplate, data: model }"></div>
</script>
<script id="nameTmpl" type="text/html">
<fieldset>
<legend>Naamgegevens</legend>
<p data-bind="css: { error: FirstName.hasError }">
@Html.LabelFor(model => model.FirstName)
@Html.TextBoxFor(model => model.FirstName, new { data_bind = "value: FirstName, valueUpdate: 'afterkeydown'"})
<span …Run Code Online (Sandbox Code Playgroud) c# ×2
javascript ×2
knockout.js ×2
asp.net ×1
asp.net-mvc ×1
fullcalendar ×1
generics ×1
polymorphism ×1
rest ×1
validation ×1
wcf-web-api ×1
wizard ×1