【发布时间】:2012-05-01 16:26:31
【问题描述】:
我正在使用 asp.net,所以它已经有一个<fomr id="aspnetForm" name="aspnetForm">。
我想要一个允许“单独提交多个表单”的页面。例如,我希望用户保存他们的简历。在“教育经验”页面上,我想允许用户的多条记录,每条记录都可以用ajax单独编辑和保存,但在ajax之前验证。
类似:
<form id="aspnetForm" name="aspnetForm">
<div class="item_edit">
1
<input type="text" class="required" name="title" />
<input type="text" class="required" name="description" />
<input type="button" class="save" value="save" />
</div>
<div class="item_edit">
2
<input type="text" class="required" name="title" />
<input type="text" class="required" name="description" />
<input type="button" class="save" value="save" />
</div>
</form>
$("input.save").click(function(){
var thediv = $(this).parent();
if(thediv.valid()){
//save with ajax
}
else{
//show error, modal window preferred
}
})
顺便说一句:如果有帮助,我正在使用backbone.js。
编辑:我的backbone.js 代码如下所示。上面的<div class="item_edit"> 是从模板渲染出来的。
APIPortfolio.Views.OtherInfoCollection = Backbone.View.extend({
el : "#otherinfo-container",
template : "#otherinfo-template",
initialize : function(options) {
this.modelList = options.modelList.models;
},
render : function() {
var self = this;
$(self.el).empty();
_.each(this.modelList, function(model) {
$(self.el).append(Mustache.to_html($(self.template).html(), model.toJSON()));
})
return this;
}
});
【问题讨论】:
-
@run 我想验证 div 中的输入/文本区域/等,就好像它们在表单中一样。我编辑了帖子。现在更清楚了吗?
-
嗨,@Shyju。我认为问题本身与backbone.js 无关。我刚刚提到它的原因是如果backbone.js 有替代解决方案/插件,我愿意接受。你知道吗?
-
为什么不使用单独的表格?
-
@BalusC asp.net 已经有一个表格。我不能在其中嵌套其他形式,对吧?
标签: jquery .net validation