I use the jquery-confirm plugin, by clicking on an element I create the following form:

$.confirm({ //сама форма title: 'Add new event.', content: '' + '<form id="eventData">' + '<div class="form-group">' + '<label>Title</label>' + '<input type="text" placeholder="Event title.." class="name form-control" name="Title" autocomplete="off" required />' + '<br />' + '<label>Additional information</label>' + '<textarea placeholder="Add some information about event" name="Additional" class="info form-control" autocomplete="off" required /> </textarea>' + '<br />' + '<label>Start date</label>' + '<input type="date" class="startDate form-control" name="StartDate" required />' + '<br />' + '<label>End date</label>' + '<input type="date" class="endDate form-control" name="EndDate" required />' + '</div>' + '</form>', buttons: { formSubmit: { text: 'Save', btnClass: 'btn-success', action: function () { //беру информацию из формы var titleF = this.$content.find('.name').val(); var additionalF = this.$content.find('.info').val(); var startDateF = this.$content.find('.startDate').val(); var endDateF = this.$content.find('.endDate').val(); //посылаю в контроллер $.ajax({ url: 'Calendar/CreateEvent', data: { title: titleF, additional: additionalF, startDate: startDateF, endDate: endDateF}, dataType: "JSON", success: function (data) { var event = { id: data.item.Id, title: data.item.Title, start: toDateFromJson(data.item.EndDate) } $('#calendar').fullCalendar('renderEvent', event, true); } }); } }, cancel: {}, }, }); 

When I click the Save button, the values ​​from input 's are transferred to the controller. In the controller, I add these values ​​to the model and send it to other layers.

Controller:

 public ActionResult CreateEvent(string title, string additional, DateTime startDate, DateTime endDate) { BLL.Model.CalendarModelItem item = new BLL.Model.CalendarModelItem { Title = title, Additional = additional, StartDate = startDate, EndDate = endDate }; calDbProv.Add(item); return Json( new { status = "success", item }, JsonRequestBehavior.AllowGet); } 

I would like to understand how from the form that is created by clicking to send to the controller immediately the model using ajax ?

Here is the model code:

 public class CalendarModelItem { public int Id { get; set; } public string Title { get; set; } public string Additional { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } } 

    1 answer 1

    Understood. You cannot send the model right away, but you can send all the data, as I did, then the model accepts them and everything works.

     public ActionResult CreateEvent(BLL.Model.CalendarModelItem item) { calDbProv.Add(item); return Json( new { status = "success", item }, JsonRequestBehavior.AllowGet); }