我使用vue.js代替Asp.Net MVC模板和 下面是代码。
@model Manage.Models.Commands.Category.UpdateCategoryViewModel
`@using (Html.BeginForm("Update", "Category", FormMethod.Post, new { Category` = Model, @class = "edit" }))
{
<div id="categoriesUpdate">
<div class="modal-content">
<div class="modal-header">
<h2>Edit Category</h2>
<button type="button" data-dismiss="modal"><i class="material-icons" aria-hidden="true"></i></button>
</div>
<div class="modal-body table-responsive" id="modal-query">
@if (ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1))
{
@Html.ValidationSummary()
}
<table class="table">
<colgroup>
<col class="col-half" />
</colgroup>
<tbody>
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.CategoryId)
@Html.HiddenFor(m => m.TenantId)
<tr>
<td>Category Name</td>
<td><input type="text" name="CategoryName" class="form-control" placeholder="Name" aria-describedby="basic-addon1" v-bind:value="model.CategoryName"></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-success">Save Changes</button>
<button class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
}
<script type="text/javascript">
$(document).ready(function () {
var app = new Vue({
el: '#categoriesUpdate',
data: {
model: @Html.Raw(Json.Encode(Model)),
errors3: @ViewData.ModelState
}
});
});
</script>
我想将ViewData错误传递给vue.js数据对象,以便我可以使用vue.js循环渲染
<ul id="example-1">
<li v-for="item in items">
{{ item.message }}
</li>
</ul>
而不是
@if (ViewData.ModelState.Values.Any(x => x.Errors.Count >= 1))
{
@Html.ValidationSummary()
}
我已经尝试了以下所有选项