【发布时间】:2016-04-22 17:05:51
【问题描述】:
我对@987654322@ 很陌生。我想用 JSON GET 检索部分视图和所有带有验证的绑定。
我的模特:
public class MyFormModel
{
[Required]
[Range(typeof(Decimal), "1", "9999")]
[Display(Name = Translations.WorkReport.PRICE_PER_UNIT)]
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#,##}")]
public decimal Price { get; set; }
[Required]
[Range(typeof(Decimal), "1", "9999")]
[Display(Name = Translations.WorkReport.QUANTITY)]
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:#,##}")]
public decimal Quantity { get; set; }
...
我的控制器:
[HttpGet]
public virtual PartialViewResult GetDataByGroupId(int groupId)
{
...
var view = PartialView("WorkReportResult", createWorkReportsListFormModel);
return view
}
我的部分观点:
@for (int i = 0; i < Model.WorksReportsFormModel.WorkReportViewModelList.Count; i++)
{
<tr>
<td class="center">
@Html.ValidationMessageFor(modelItem => Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Price)
@Html.TextBoxFor(modelItem => Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Price,
new
{
@Value = Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Price != 0 ? Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Price.ToString() : "",
id = @Html.RenderNumbers("Price", i),
@class = "input-small focused"
})
</td>
<td class="center">
@Html.ValidationMessageFor(modelItem => Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Quantity)
@Html.TextBoxFor(modelItem => Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Quantity,
new
{
@Value = Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Quantity != 0 ? Model.WorksReportsFormModel.WorkReportViewModelList[i].WorkReportFormModel.Quantity.ToString() : "",
id = @Html.RenderNumbers("Quantity", i),
@class = "input-small focused"
})
</td>
我的正常看法:
<table class="table table-striped table-bordered bootstrap-datatable datatable dataTable grid-table" id="students">
<thead>
<tr>
<th class="grid-header"><div class="grid-header-title">Price</div></th>
<th class="grid-header"><div class="grid-header-title">Wuantity</div></th>
</tr>
</thead>
<tbody id="content">
</tbody>
</table>
我从这个视图调用 JQUERY 来检索局部视图:
$.ajax({
type: 'GET',
timeout: 30000,
url: '' + baseurl + '/CustomModel/ManageWorkReport/GetDataByGroupId',
data: { groupId: value},
cache: false,
success: function (data) {
if (data) {
$("#content").html(data);
...
但是不行,这里没有绑定。如何包含KnockoutJS?
我找到了这个但不起作用! https://stevemgentile.wordpress.com/2012/10/07/knockoutjs-asp-net-mvc-partial-view-loading/
【问题讨论】:
-
我很困惑:您的问题代码中有 zero 与淘汰相关的代码位吗?没有
data-bindings,没有客户端视图模型,没有applyBindings,没有,据我所知。您对我们有什么期望? -
@Jeroen 我想他想将此代码转换为使用 Knockout。
-
@JoseLuis 可能是,但在这种情况下,这是一个非常 广泛的问题,甚至可能更多的是(架构)设计问题,与 Stack Overflow 的主题不太相关。
标签: jquery asp.net asp.net-mvc knockout.js