0
我有一個網格填充筆記,我希望能夠添加一個新的筆記。這可以使用兩種不同的視圖,但是這使得CreateNote視圖打開一個新窗口。我想在同一個窗口中打開它。因此,而不是視圖我使用PartialView。這是有效的,但「@using(UI.koform(Model,null))」被視爲html,所以knockoutjs不起作用。我怎樣才能在局部視圖中完成這項工作?如何在部分視圖中使用@using?
代碼:
的觀點:
[...]
<script type="text/javascript">
(function() {
$('#load-partial').click(function() {
$('#partial').load('@Url.Action("CreateNote", "Entity", new {modelEntity = @Model.meta.entity})');
});
})();
</script>
<div id="partial"></div>
<button type="button" id="load-partial">Create Note</button>
行動:
public ActionResult CreateNote(
[ModelBinder(typeof(Models.JsonModelBinder))]
NoteModel Model, string cmd, string modelEntity)
{
[...]
return PartialView("CreateNotePartial",Model);
}
局部視圖:
<%@ Control Language="C#" Inherits="test.Web.Framework.Core.ViewUserControl<test.Web.Framework.Areas.Administration.Models.NoteModel>" %>
@using (UI.koform(Model, null))
{
<div class="ui-state-highlight ui-corner-all highlight" data-bind="visible: meta.message">
<span class="ui-icon ui-icon-info"></span><strong data-bind="text: meta.message">
</strong>
</div>
Subject:
<input type="text" data-bind="value:subject" />
<span data-bind="text: subject"></span>
<br />
Text:
<input type="text" data-bind="value:text" />
<br />
<a href="#" data-bind="click:function(){setvalues() }">set values</a>
<div class="dialogButtons">
<button onclick="$('#@Model.meta.modelname').koform('submit');">
Save</button>
</div>
}
爲什麼你要在幾個地方混在您的局部視圖''標籤? – 2011-12-29 14:07:57
我還是這麼做的,因爲我從視圖中複製了它,在沒有標記的情況下它不起作用,現在將其刪除。仍然有同樣的問題。 – 2011-12-29 14:14:19
等一下,你可以混合webforms <% %>語法與剃刀的@? – 2011-12-29 14:20:15