Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please let me know how to fix the issue. This should be simple but not working.

1. Have a Controller, returning model to an Index razor
2. Index razor passes one viewmodel to a partialview
3. Here in partial view, trying to bind the whole model with Knockoutjs.


// Controller


public ActionResult Index()
{

Books = db.BookDB.ToList();
Authors = db.AuthorDB.ToList();
objBookAuthorViewModel.Authors = Authors;
objBookAuthorViewModel.Books = Books;
return View("~/Views/Book/Index.cshtml", objBookAuthorViewModel);
}


/// Partial view
@using KnockOutJsMvcCreateArticle.Models
@using Newtonsoft.Json;
@model IEnumerable<knockoutjsmvccreatearticle.models.author>

<script src="~/Scripts/Knockout.mapping-2.4.1.js"></script>



@{
ViewBag.Title = "Authors";
}

@Html.ActionLink("Create New", "Create")


@Model.Count()





@Html.DisplayNameFor(model => model.FirstName) @Html.DisplayNameFor(model => model.LastName)


<script type="text/javascript">
var viewModel = @Html.Raw(Json.Encode(Model));
ko.applyBindings(viewModel);
</script>


//Index View
@model KnockOutJsMvcCreateArticle.Models.BookAuthorViewModel
@using KnockOutJsMvcCreateArticle.Models
@using Newtonsoft.Json;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}





# of Authors @Model.Authors.Count




@Html.Partial("~/Views/Shared/_Author.cshtml", Model.Authors)







@section Scripts {

<script type="text/javascript"
src="@Url.Content("~/scripts/jquery.unobtrusive-ajax.js")"></script>

}
Posted

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