我正在使用C#和.NET Framework 4.5.1开发ASP.NET MVC 5 Web.
我form在一个cshtml文件中有这个:
@model MyProduct.Web.API.Models.ConnectBatchProductViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Create</title>
</head>
<body>
@if (@Model != null)
{
<h4>Producto: @Model.Product.ProductCode, Cantidad: @Model.ExternalCodesForThisProduct</h4>
using (Html.BeginForm("Save", "ConnectBatchProduct", FormMethod.Post))
{
@Html.HiddenFor(model => model.Product.Id, new { @id = "productId", @Name = "productId" });
<div>
<table id ="batchTable" class="order-list">
<thead>
<tr>
<td>Cantidad</td>
<td>Lote</td>
</tr>
</thead>
<tbody>
<tr>
<td>@Html.TextBox("ConnectBatchProductViewModel.BatchProducts[0].Quantity")</td>
<td>@Html.TextBox("ConnectBatchProductViewModel.BatchProducts[0].BatchName")</td>
<td><a class="deleteRow"></a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5" style="text-align: left;"> …Run Code Online (Sandbox Code Playgroud) 我在视图中添加了一个按钮.单击此按钮时,将添加部分视图.在我的表单中,我可以添加尽可能多的局部视图.提交此表单数据时,我无法将所有部分视图数据发送到控制器.我创建了一个具有所有属性的不同模型,并且我已经将该模型的列表添加到我的主模型中.任何人都可以给我一些技巧,以便我可以将所有部分视图内容发送到我的控制器?
在我看来
<div id="CSQGroup">
</div>
<div>
<input type="button" value="Add Field" id="addField" onclick="addFieldss()" />
</div>
function addFieldss()
{
$.ajax({
url: '@Url.Content("~/AdminProduct/GetColorSizeQty")',
type: 'GET',
success:function(result) {
var newDiv = $(document.createElement("div")).attr("id", 'CSQ' + myCounter);
newDiv.html(result);
newDiv.appendTo("#CSQGroup");
myCounter++;
},
error: function(result) {
alert("Failure");
}
});
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中
public ActionResult GetColorSizeQty()
{
var data = new AdminProductDetailModel();
data.colorList = commonCore.getallTypeofList("color");
data.sizeList = commonCore.getallTypeofList("size");
return PartialView(data);
}
[HttpPost]
public ActionResult AddDetail(AdminProductDetailModel model)
{
....
}
Run Code Online (Sandbox Code Playgroud)
在我的部分视图中
@model IKLE.Model.ProductModel.AdminProductDetailModel
<div class="editor-field">
@Html.LabelFor(model => model.fkConfigChoiceCategorySizeId)
@Html.DropDownListFor(model => model.fkConfigChoiceCategorySizeId, …Run Code Online (Sandbox Code Playgroud) 我有一个表有一行动态文本框.示例如下:

我通过单击[+]添加新目标在表格中添加行,它将出现在屏幕下方:

我想将验证类添加到表格内的所有文本框中.因此,当用户单击"保存"按钮时,它将检查所有文本框.
我尝试使用这个jquery:
$('#tbTargetDetails tr').each(function () {
$(this).find('td input:text').each(function (i,a) {
// get each of the textbox and add validation class to it
});
});
Run Code Online (Sandbox Code Playgroud)
我正在使用MVC 5,jquery-1.10.2.js,jquery-1.10.2.min.js,jquery.validate*和Site.css,它们具有类input.input-validation-error
在我的模特中:
public class ClsTargetInfo
{
public string ItemNumber_Target { get; set; }
[Required]
public string TargetColor_U { get; set; }
[Required]
public string TargetColor_V { get; set; }
[Required]
public string D90Target_U { get; set; }
[Required]
public string D90Target_V { get; set; }
[Required]
public string D10Target_U { get; set; …Run Code Online (Sandbox Code Playgroud)