c# - 如何在部分 View 中使用@using?

标签 c# javascript knockout.js asp.net-mvc-partialview

我有一个充满注释的网格,我希望能够添加新注释。这可以使用两个不同的 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/

相关文章:

c# - WPF:单击嵌套在 Canvas 中的路径检测

c# - 使用异步数据读取器

c# - 在 C# 中使用 Regex 比较两个不同的文件夹

javascript - 自动滚动滚动条Javascript

javascript - 试图让按钮发挥作用,但我的警报弹出了书面脚本

knockout.js - froala 的自定义 knockout 绑定(bind)使编辑失去焦点

javascript - 为什么这个 setTimeout 根本不触发?

c# - 每种语言的 sitecore 中最受欢迎的项目。

javascript - 字符串过滤。需要去掉&lt;style&gt;标签及其内容,只保留<body>中的内容

javascript - knockout 延期问题 - 更好的解决方案?