2011-12-29 22 views
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> 
} 
+0

爲什麼你要在幾個地方混在您的局部視圖''標籤? – 2011-12-29 14:07:57

+0

我還是這麼做的,因爲我從視圖中複製了它,在沒有標記的情況下它不起作用,現在將其刪除。仍然有同樣的問題。 – 2011-12-29 14:14:19

+1

等一下,你可以混合webforms <% %>語法與剃刀的@? – 2011-12-29 14:20:15

回答

2

它看起來像你的混合視圖引擎。您的控制定義使用ASPX視圖引擎語法(<%@ %>),而您的using聲明使用的是Razor。我的猜測是,如果你改變了代碼,這會工作:

<% using (UI.koform(Model, null)) 
{ %> 

<%-- HTML --%> 

<% } %> 
+0

工作,謝謝! – 2011-12-29 15:00:23

相關問題