I have the following data model:
public class Training
{
public Training()
{
this.ID = 0;
this.Name = null;
this.Instructor = null;
this.StartDate = DateTime.Now;
this.EndDate = DateTime.Now;
this.Time = null;
this.Duration = null;
}
public Training(int id, string name, string instructor, DateTime startdate, DateTime enddate, string time, string duration)
{
this.ID = id;
this.Name = name;
this.Instructor = instructor;
this.StartDate = startdate;
this.EndDate = enddate;
this.Time = time;
this.Duration = duration;
}
public Training(int id, string instructor)
{
this.ID = id;
this.Instructor = instructor;
}
public int ID { get; set; }
public string Name { get; set; }
public string Instructor { get; set; }
[DisplayFormat(DataFormatString = "{0:d MMM yyyy}")]
public DateTime StartDate { get; set; }
[DisplayFormat(DataFormatString = "{0:d MMM yyyy}")]
public DateTime EndDate { get; set; }
public string Time { get; set; }
public string Duration { get; set; }
}
I have the following partial view called "CreatePartialView.cshtml"
<table>
<tr>
<td></td>
<td>Training Name</td>
<td>
<input type="text" id="trainingname" /></td>
</tr>
<tr>
<td></td>
<td>Instructor Name</td>
<td>
<select id="selectInstructor">
<option selected="selected">Select Instructor</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>Select Time</td>
<td>
<input id="timepicker" />
</td>
</tr>
<tr>
<td></td>
<td>Start Date</td>
<td>
<input id="startdatepicker" />
</td>
</tr>
<tr>
<td></td>
<td>End Date</td>
<td>
<input id="enddatepicker" />
</td>
</tr>
<tr>
<td></td>
<td>Duration</td>
<td>
<input type="text" id="duration" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="button" value="Submit" id="submit-button" class="btnStyleOne" />
</td>
</tr>
and i have de follwing code
$("#submit-button").click(function () {
// On submit button click close dialog box
$("#createForm").dialog("close");
//Set inserted values
var name = $("#trainingname").val();
var selectInstructor = $("#selectInstructor").val();
var startdatepicker = $("#startdatepicker").val();
var enddatepicker = $("#enddatepicker").val();
var timepicker = $("#timepicker").val();
var duration = $("#duration").val();
// Call Create action method
$.post('/Home/Create', { "name": name,
"instructor": selectInstructor, "startdate": startdatepicker,
"enddate": enddatepicker,
"time": timepicker, "duration": duration },
function () {
alert("data is posted successfully");
window.location.reload(true);
});
In HomeController, we call InsertTraining() method of repository to save data in database.
[HttpPost]
public void Create(Training training)
{
_trainingRepository.InsertTraining(training);
}
and before cilcking on submit-button i must validate the form of CreatePartialview.cshtml ,how can I do it?
Ok, there's a lot of things you haven't covered on your project or have not specified in your question. The answer would be too long and I would suggest to read a tutorial and then come back with any more specific questions. Read this
http://msdn.microsoft.com/en-us/library/ee256141(v=vs.100).aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.