Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
Visual studio doesn't understand method InitializeViewBag("Simple list") from example below. Please, help

Model
C#
public class SimpleListModel
{
public string ItemToAdd { get; set; }
public List<string> Items { get; set; }

public void AddItem()
{
Items.Add(ItemToAdd);
ItemToAdd = "";
}
}

Razor
C#
@using PerpetuumSoft.Knockout
@model KnockoutMvcDemo.Models.SimpleListModel
@{
var ko = Html.CreateKnockoutContext();
}
@using (ko.Html.Form("AddItem", "SimpleList", null, new { id = "myform" }))
{
<span>New item:</span>
@ko.Html.TextBox(m => m.ItemToAdd).ValueUpdate(KnockoutValueUpdateKind.AfterKeyDow n) 
<button type="submit" @ko.Bind.Enable(m => m.ItemToAdd.Length > 0)>Add</button>
<p>Your items:</p>
@ko.Html.ListBox(m => m.Items, new { width = 50, size = 7 }) 
} 
<script type="text/javascript"> 
$('#myform').ajaxForm();
</script> 

@ko.Apply(Model)

Controller
C#
public class SimpleListController : BaseController
{
public ActionResult Index()
{
InitializeViewBag("Simple list");
var model = new SimpleListModel { Items = new List<string> { "Alpha", "Beta", "Gamma" } };
return View(model);
}

public ActionResult AddItem(SimpleListModel model)
{
model.AddItem();
return Json(model);
}
}
Posted
Updated 13-Sep-13 7:23am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900