سلام
من از UiHint برای نمایش PersianDatePicker استفاده میکنم حالا وقتی فرم رو ارسال میکنم مقادیر DateTime های فرم نال ارسال میشن علتش چی می تونه باشه؟ممنون کمک کنید
UiHint در MVC 4 استفاده میشد و در 5 استفاده ای ندارد
دلیل خاصی برای استفاده ازش دارید ؟
به صورت معمولی استفاده کنید و تست کنید
آقای مدائنی من میخواستم با استفاده از UiHint دیگه مجبور نشم DateTimepicker ها رو در هر فرمی دستی اضافه کنم و فقط با dataannotation این کار راحت تر انجام میشه و هر نوع دیت تایمی از این UiHint خونده میشه .
حالا کار شما رو هم انجام دادم ولی بازم همون مشکل رو دارم و دوباره نال رد میکنه .
کد ویو و کنترلر را قرار دهید
اکشن پروژه [HttpPost] public virtual ActionResult AddStudentForms(StudentVM studentVm) { if (!Request.IsAjaxRequest()) { ModelState.AddModelError("", "در پر کردن فیلد ها دقت لازم را انجام داده سپس اطلاعات را ارسال نمایید"); return PartialView("_AddStudentForm", studentVm); } if (studentVm == null) return PartialView("_AddStudentForm", studentVm); var student = new Student { Id = Guid.NewGuid(), Name = studentVm.Name, LastName = studentVm.LastName, Address = studentVm.Address, RegisterDate = studentVm.RegistrationDate, BirthDay = studentVm.BirthDay, Email = studentVm.Email, Password = studentVm.Password, Phone = studentVm.Phone, UserName = studentVm.UserName, StudentNumber = studentVm.StudentNumber, Branches = new List<Branch> { new Branch {Id =Guid.NewGuid() ,Name = studentVm.Braches.ToString() } }, UserId = Guid.NewGuid() }; try { db.Students.Add(student); db.SaveChanges(); } catch (Exception exception) { ModelState.AddModelError("", exception.Message); } return PartialView("_AddStudentForm", studentVm); }
این هم پارشیال ویویی که در داخل مودال قسمت بدنه مودال نمایش اده میشه
@model University.Areas.Admin.Models.StudentVM @using (Ajax.BeginForm(new AjaxOptions { AllowCache = false, HttpMethod = "POST", OnFailure = "failure", OnSuccess = "success", UpdateTargetId = "studenttable" })) { @Html.AntiForgeryToken() <div class="form-horizontal"> <div class="form-group"> @Html.LabelFor(x => x.Name, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.Name, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.Name) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.LastName, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.LastName, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.LastName) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.BirthDay, new { @class = "control-label col-sm-3 " }) <div class="col-sm-9"> @Html.EditorFor(m => m.BirthDay, new { @class = "form-control required" }) @*@Html.TextBoxFor(item => item.BirthDay, new { @class = "form-control required ", data_MdDateTimePicker = "true", data_TargetSelector = "#BirthDay", data_EnableTimePicker = "true", data_Placement = "left", data_Trigger = "click" })*@ </div> <div> @Html.ValidationMessageFor(m => m.BirthDay) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.Email, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.Email, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.Email) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.UserName, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.UserName, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.UserName) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.Password, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.Password, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.Password) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.Phone, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.Phone, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.Phone) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.RegistrationDate, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.EditorFor(m => m.RegistrationDate, new { @class = "form-control required" }) @*@Html.TextBoxFor(item => item.RegistrationDate, new { @class = "form-control required ", data_MdDateTimePicker = "true", data_TargetSelector = "#RegistrationDate", data_EnableTimePicker = "true", data_Placement = "left", data_Trigger = "click" })*@ </div> <div> @Html.ValidationMessageFor(m => m.RegistrationDate) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.StudentNumber, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextBoxFor(m => m.StudentNumber, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.StudentNumber) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.Address, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.TextAreaFor(m => m.Address, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.Address) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.Braches, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @Html.EnumDropDownListFor(m => m.Braches, new { @class = "form-control required" }) </div> <div> @Html.ValidationMessageFor(m => m.Braches) </div> </div> <div class="form-group"> @Html.LabelFor(x => x.Avatar, new { @class = "control-label col-sm-3" }) <div class="col-sm-9"> @*@Html.EditorFor(m => m.Avatar, new { @class = "form-control required" })*@ <input type="file" class="form-control required" id="avatar" onchange="readURL(this)" /> <img width="150" height="150" id="img" alt="image" class="thumbnail" /> </div> <div> @*@html.validationmessagefor(m => m.avatar)*@ </div> </div> <div class="modal-footer"> <input type="button" class="btn btn-success" data-dismiss="modal" value="بستن" /> <input type="submit" id="substudent" class="btn btn-success" value="ذخیره" /> </div> </div> }
فهمیدم مشکل از کجاست
ویو مدل من پراپرتی BirthDay و RegistrationDate هاش از نوع DateTime هست و چون DateTimePicker من فارسی هست به ویو مدلم بایند نمی شه و به اکشنفرستاده نمیشه .
وقتی Propertyها رو از نوع string گرفتم مشکل حل شد و به اکشن ارسال شد .
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)