【发布时间】:2015-07-17 15:38:46
【问题描述】:
我按照本教程:http://knockoutmvc.com/GiftList 创建可食用列表。 但是当我运行代码时。它注意到一个错误,
找不到类型或命名空间名称“PerpetuumSoft”(您是 缺少 using 指令或程序集引用?)
这一行的错误:
@model MvcMovie.Models.GiftListModel
@using PerpetuumSoft.Knockout //Error in this line
@{
ViewBag.Title = "Index";
}
@{
var ko = Html.CreateKnockoutContext(); //and also Error in this line
}
我在捆绑中包含淘汰赛
bundles.Add(new ScriptBundle("~/bundles/knockout").Include(
"~/Scripts/knockout-2.1.0.js",
"~/Scripts/knockout-2.1.0.debug.js"));
并将此代码添加到共享布局名称_Layout.cstml
@Scripts.Render("~/bundles/knockout")
实际上,我搜索本教程是因为我想创建一个用户可以编辑列表的视图,数据只有在用户单击按钮保存时才能保存,这意味着用户可以做任何他们想做的事情。仅在触发按钮保存时更新数据库。如果您知道任何其他不使用任何扩展或插件的方法,请推荐它(因为我必须使用 ASP .NET MVC 4 Only,不再添加任何扩展)。非常感谢。
这是代码
@model MvcMovie.Models.GiftListModel
@using PerpetuumSoft.Knockout
@{
ViewBag.Title = "Index";
}
@{
var ko = Html.CreateKnockoutContext();
}
<p>You have asked for @ko.Html.Span(m => m.Gifts.Count) gift(s)</p>
<form id="myform">
<table>
<tbody>
@using (var items = ko.Foreach(m => m.Gifts))
{
<tr>
<td>Gift name:@items.Html.TextBox(item => item.Title, new { @class = "required" }).UniqueName()</td>
<td>Price: $@items.Html.TextBox(item => item.Price, new { @class = "required number" }).UniqueName()</td>
<td>@ko.Html.Button("Delete", "RemoveGift", "GiftList", new { index = items.GetIndex() })</td>
</tr>
}
</tbody>
</table>
@ko.Html.Button("Add", "AddGift", "GiftList")
<button @ko.Bind.Enable(m => m.Gifts.Count > 0) type="submit">Save</button>
</form>
@using (ko.If(m => m.ServerTime.Length > 0))
{
<p>Saved at @ko.Html.Span(m => m.ServerTime)</p>
}
<script type="text/javascript">
$("#myform").ajaxForm();
$("#myform").validate({ submitHandler: function () { @ko.ServerAction("Save", "GiftList"); } });
</script>
<style scoped="scoped">
input.error {
border: 1px solid red;
background-color: #FDC;
}
label.error {
display: block;
color: Red;
font-size: 0.8em;
}
</style>
@ko.Apply(Model)
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 razor knockout.js