Hi,
I have a listing page. and in that page i have a button to add new item.
When i click on the add new button, a popup displays and in that popup i need to add the new item and save.
Popup contains textboxes and dropdown controls. Now when i click save the data entered in textboxes get saved but the selected data from dropdown is not getting saved. Please help me to do this.
This the code what i have written:
In API controller:
public HttpResponseMessage Post(TKTJOB job)
{
HelpDeskRepository.AddJob(job);
var response = Request.CreateResponse<TKTJOB>(HttpStatusCode.Created, job);
string uri = Url.Link("DefaultApi", new { id = job.JobId });
return response;
}
In My.js
$(document).ready(function () {
ko.applyBindings(new HelpDesk(), document.getElementById('full'));
});
function HelpDesk() {
var self = this;
self.JobID=0 ;
self.CategoryId=0;
self.JobTitle="";
self.JobDesc="";
self.category = ko.observable([]);
self.categorySelected = ko.observable();
$.getJSON("api/helpdeskapi/getCategory", function (data) {
self.category(data);
});
self.addTicket = function () {
$.ajax({
url: "api/helpdeskapi/Post",
type: 'post',
data: ko.toJSON(this),
contentType: 'application/json',
success: function (result) { }
});
}
}
In popup:
<select style = "font-size: 12px; font-weight: normal;" data-bind="options: category, optionsText: 'Category',optionsValue: 'CategoryId',Value: categorySelected, optionsCaption: '........Select........'"></select>