I have a grid filled with notes and I want to be able to add a new note. This works using two different views, but that makes the CreateNote view open a new window. I want this to open in the same window. So instead of a View I use a PartialView. This works, but the “@using (UI.koform(Model, null))” is seen as html so the knockoutjs doesn’t work. How can I make this work in a partial view?
Code:
The 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>
The action:
public ActionResult CreateNote(
[ModelBinder(typeof(Models.JsonModelBinder))]
NoteModel Model, string cmd, string modelEntity)
{
[...]
return PartialView("CreateNotePartial",Model);
}
The Partial 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>
}
It looks like you’re mixing View engines. Your control definition is using ASPX View engine syntax (
<%@ %>) while yourusingstatement is using Razor. My guess is if you changed the code to this it would work: