Hi
i'm trying to post model to a web api where every time only one item in the model shown up at post method. like if i'm posting a model called Movie ,Id and Title are the properties of this model.
so here my problem is when i'm trying to post it from client side using knockout.js,only Title value is coming in the web api post method.
post method in api
[HttpPost]
[ODataRoute("CreateMovie")]
public IHttpActionResult CreateMovie(Movie parameters)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
string title = "Test";
Movie movie = new Movie()
{
Title = title,
ID = _db.Movies.Count + 1,
};
_db.Movies.Add(movie);
return Created(movie);
}
client side code:
window.viewModel = (function () {
var self = this;
self.movies = ko.observableArray();
self.id = ko.observable();
self.title = ko.observable();
self.year = ko.observable();
self.duedate = ko.observable();
self.ischeckedout = ko.observable();
self.errorMessage = ko.observable();
self.createMovie = function () {
var movieVal = { ID: self.id(), Title: self.title(), Year: self.year(), DueDate: null, IsCheckedOut: self.ischeckedout() };
ajaxRequest("post", "odata/CreateMovie",movieVal)
.done(function (result) {
self.movies.push(new movie(result))
})
.fail(function (jqXHR, textStatus, errorThrown) {
self.errorMessage(errorThrown);
});
}
function ajaxRequest(type, url, data) {
debugger;
var options = {
dataType: "json",
contentType: "application/json",
type: type,
data: data ? ko.toJSON(data) : null
};
self.errorMessage(null);
return $.ajax(url, options);
}
})();
$(document).ready(function () {
ko.applyBindings(viewModel);
});
So in web api post methdo only Title is showing up every time not all other items.
suggest me on this.
Thanks in advance