我有一个充满注释的网格,我希望能够添加新注释。这可以使用两个不同的 View ,但这会使 CreateNote View 打开一个新窗口。我希望它在同一个窗口中打开。因此,我使用 PartialView 代替 View。这是可行的,但“@using (UI.koform(Model, null))”被视为html,因此knockoutjs不起作用。我怎样才能在部分 View 中完成这项工作?
代码:
View :
[...]
<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>
Action :
public ActionResult CreateNote(
[ModelBinder(typeof(Models.JsonModelBinder))]
NoteModel Model, string cmd, string modelEntity)
{
[...]
return PartialView("CreateNotePartial",Model);
}
部分 View :
<%@ 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>
}
最佳答案
看起来您正在混合查看引擎。您的控件定义使用 ASPX View 引擎语法 ( <%@ %>
),而您的 using
声明正在使用 Razor。我的猜测是,如果您将代码更改为这样,它就会起作用:
<% using (UI.koform(Model, null))
{ %>
<%-- HTML --%>
<% } %>
关于c# - 如何在部分 View 中使用@using?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8667770/