سلام
من کلاس PesianCulture رو توو پروژه گذاشتم و توو Globalam کدشو نوشتم
protected void Application_BeginRequest(object sender, EventArgs e) { var persianCulture = new GSD.Globalization.PersianCulture(); Thread.CurrentThread.CurrentCulture = persianCulture; Thread.CurrentThread.CurrentUICulture = persianCulture; }
آقای مدائنی چرا توو کندو گرید همچنان فارسی نشون نمیده؟
شرمنده میدونم خیلی سوال میپرسم
من خیلی شوت هم نیستم اما این پروژه فورست ماژوله و خیلی هم گیر داره
اگه دیر تحویل بدم منجر به پرداخت خسارت میشم
ممنونم از پاسخ گویی و راهنماییتون
خدا خیرتون بده
تاریخ را در بانک چگونه ذخیره کردید ؟
احیانا از نوع nvarchar که نیست ؟
سلام
نه نوعش datatime و میتونه null هم باشه
کد view و کدهای action را قرار دهید
این کد ویو فقط کد کندو گریدمو گذاشتم
@(Html.Kendo().Grid<CMScharge.Classes.Building.unitproperties>() .Name("gridd") .Columns(columns => { columns.Bound(p => p.UnitProperties_id).Visible(false); columns.Bound(p => p.UnitProperties_EnterDate).Title("تاریخ ورود"); columns.Bound(p => p.UnitProperties_Name).Title("نام مالک/مستأجر"); columns.Bound(p => p.UnitProperties_Mobile).Title("تلفن همراه"); columns.Bound(p => p.UnitProperties_Tell).Title("تلفن"); columns.Bound(p => p.UnitProperties_Email).Title("ایمیل"); columns.Bound(p => p.UnitProperties_Owner).ClientTemplate("<input name='UnitProperties_Owner' type='checkbox' data-bind='checked: UnitProperties_Owner' #= UnitProperties_Owner ? checked='checked' : '' # disabled />").Title("مالک"); columns.Bound(p => p.UnitProperties_Active).ClientTemplate("<input name='UnitProperties_Active' type='checkbox' data-bind='checked: UnitProperties_Active' #= UnitProperties_Active ? checked='checked' : '' # disabled/>").Title("فعال"); columns.Template(x => { }).ClientTemplate("<input type='button' value='ویرایش' onclick='EditMobileTell(#=UnitProperties_id#)' class='k-button k-grid-even' />"); columns.Command(command => { command.Destroy().HtmlAttributes(new { @class = "k-button k-button-icontext" }).Text("حذف"); }); }) .Pageable(pageable => pageable .Messages(message => message.ItemsPerPage("تعداد آیتم در هر صفحه")) .Messages(message => message.Display("نمایش افراد {0} تا {1}. تعداد کل افراد مرتبط با این واحد :{2}")) .Refresh(true) .PageSizes(true) .ButtonCount(2) ) .Editable(editable => { editable.DisplayDeleteConfirmation("از حذف مطمئن هستید؟"); }) .Sortable() .DataSource(c => c .Ajax() .ServerOperation(false) .PageSize(3) .Events(events => events.Error("error_handler")) .Model(model => { model.Id(p => p.UnitProperties_id); model.Field(p => p.UnitProperties_id).Editable(false); }) .Read(read => read.Action("AllMobileTell", "Building")) .Destroy(update => update.Action("DeleteMobileTell", "Building")) ) )
اینم کد اکشنم
public ActionResult AllMobileTell([DataSourceRequest] DataSourceRequest request) { DataSourceResult result = new DataSourceResult(); try { dbCMSEntities d = new dbCMSEntities(); List<unitproperties> lst = new List<unitproperties>(); int id = 0; if (HttpContext.Application.Count > 0 && HttpContext.Application["unit_id"] != null) id = (int)HttpContext.Application["unit_id"]; var AllMobileTell = d.UnitProperties.Where(c => c.UnitProperties_UnitId == id).ToList(); if (AllMobileTell.Count > 0) { lst = AllMobileTell.Select(c => new unitproperties() { UnitProperties_Active = c.UnitProperties_Active, UnitProperties_Email = c.UnitProperties_Email, UnitProperties_EnterDate = c.UnitProperties_EnterDate, UnitProperties_id = c.UnitProperties_id, UnitProperties_Mobile = c.UnitProperties_Mobile, UnitProperties_Name = c.UnitProperties_Name, UnitProperties_Owner = c.UnitProperties_Owner, UnitProperties_Tell = c.UnitProperties_Tell, UnitProperties_UnitId = c.UnitProperties_UnitId }).ToList(); result = lst.ToDataSourceResult(request); } d.Dispose(); } catch (Exception) { } return Json(result); }
به نظرم مشکل از خروجی Json هست
به صورت عادی Return کنید ببینید مشکل برطرف میشه یا خیر ؟
اگر شد باید خودتون تاریو رو شمسی کنید
به صورت عادی چه جوری برگردونم؟
بزنیم return view؟ منظورتون اینه؟
به صورت عادی نمیشه یعنی من ویوم یه جوریه نمیتونم عادی برگردونم
به صورت عادی منظورتون اینه مثلا من ویوم از یه نوع viewMOdel هست داخلش یه لیست داشته باشم که اون لیست رو وصل کنم به گرید ؟ و دیگه توو گرید نگم برو از اکشن فلان بخوون؟منظورتون این؟
اگر بخواهیم توو گرید مثلا چند تا textbox باشه که کاربر تووش داده وارد کنه چه رویدادی داره گردی که اون چیزهای وارد شده رو مدیریت کرد؟
بله Return view کنید و از Model استفاده کنید
سوال دومم رو هم یه کم راهنمایی می کنید من میخوام توو گریدم چند تا textbox نشون بدم که کاربر تووش داده وارد کنه بعد مثلا توو هر ردیفم دکمه ثبت داشته باشم ثبت رو زد ببرم ذخیره کنم
اینو نمیدونم چه جوری پیاده کنم؟
میتونید هر ردیف را داخل Form قرار دهید و با زدن دکمه submit کنار هر خط اطلاعات اون خط رو به Action مربوطه ارسال کنید
ببینید من دقیقا همچین چیزی میخوام توو هر ردیف نام بلوک و تعدادشو وارد کنه بهد دکمه ثبت اصلا بیرونه زد بره بلوک و واحد ایجاد کنه
متوجه نشدم شما میگید اصلا گرید نزارم ؟ وبیام مثلا یه foreach بزارم و واسه هر ردیف فرم بزارم؟
اون تاریخ خا فارسی نشد حتی عادی با مدل پر کردم بازم نشد کدمو ببینید
این گرید
@(Html.Kendo().Grid<CMScharge.Classes.Building.unitproperties>(Model.listTellMobile) .Name("gridd") .Columns(columns => { columns.Bound(p => p.UnitProperties_id).Visible(false); columns.Bound(p => p.UnitProperties_EnterDate).Title("تاریخ ورود"); columns.Bound(p => p.UnitProperties_Name).Title("نام مالک/مستأجر"); columns.Bound(p => p.UnitProperties_Mobile).Title("تلفن همراه"); columns.Bound(p => p.UnitProperties_Tell).Title("تلفن"); columns.Bound(p => p.UnitProperties_Email).Title("ایمیل"); columns.Bound(p => p.UnitProperties_Owner).ClientTemplate("<input name='UnitProperties_Owner' type='checkbox' data-bind='checked: UnitProperties_Owner' #= UnitProperties_Owner ? checked='checked' : '' # disabled />").Title("مالک"); columns.Bound(p => p.UnitProperties_Active).ClientTemplate("<input name='UnitProperties_Active' type='checkbox' data-bind='checked: UnitProperties_Active' #= UnitProperties_Active ? checked='checked' : '' # disabled/>").Title("فعال"); columns.Template(x => { }).ClientTemplate("<input type='button' value='ویرایش' onclick='EditMobileTell(#=UnitProperties_id#)' class='k-button k-grid-even' />"); columns.Command(command => { command.Destroy().HtmlAttributes(new { @class = "k-button k-button-icontext" }).Text("حذف"); }); }) .Pageable(pageable => pageable .Messages(message => message.ItemsPerPage("تعداد آیتم در هر صفحه")) .Messages(message => message.Display("نمایش افراد {0} تا {1}. تعداد کل افراد مرتبط با این واحد :{2}")) .Refresh(true) .PageSizes(true) .ButtonCount(2) ) .Editable(editable => { editable.DisplayDeleteConfirmation("از حذف مطمئن هستید؟"); }) .Sortable() .DataSource(c => c .Ajax() .ServerOperation(false) .PageSize(3) .Events(events => events.Error("error_handler")) .Model(model => { model.Id(p => p.UnitProperties_id); model.Field(p => p.UnitProperties_id).Editable(false); }) //.Read(read => read.Action("AllMobileTell", "Building")) .Destroy(update => update.Action("DeleteMobileTell", "Building")) ) )
اینم کد اکشنی که مدل رو پر میکنه
[HttpGet] public ActionResult UpdateUnit(int id) { try { if (id != 0) { System.Web.HttpContext.Current.Application.Lock(); System.Web.HttpContext.Current.Application["unit_id"] = id; System.Web.HttpContext.Current.Application.UnLock(); dbCMSEntities d = new dbCMSEntities(); var query = d.Unit.Where(c => c.Unit_id == id).FirstOrDefault(); if (query != null) { short default_short = 0; byte default_byte = 0; BuildingUnitProperties item = new BuildingUnitProperties(); item.Area = query.Unit_Area != null ? query.Unit_Area.Value : default_short; item.NumberResidents = query.Unit_NumberResidents != null ? query.Unit_NumberResidents.Value : default_byte; item.NumberParking = query.Unit_NumberParking != null ? query.Unit_NumberParking.Value : default_byte; item.Charje = query.Unit_DefaultCharge != null ? query.Unit_DefaultCharge.Value : 0; item.Floor = query.Unit_Floor != null ? query.Unit_Floor.Value : default_byte; item.Description = query.Unit_Description; item.Warehouse = query.Unit_Warehouse != null ? query.Unit_Warehouse.Value : default_byte; item.Title = query.Unit_Title; item.Number = query.Unit_Number != null ? query.Unit_Number.Value : default_byte; item.listTellMobile = (from p in d.UnitProperties.Where(c => c.UnitProperties_UnitId == id).ToList() select new unitproperties() { UnitProperties_Active =p.UnitProperties_Active , UnitProperties_Email=p.UnitProperties_Email , UnitProperties_EnterDate =p.UnitProperties_EnterDate , UnitProperties_id =p.UnitProperties_id , UnitProperties_Mobile =p.UnitProperties_Mobile , UnitProperties_Name =p.UnitProperties_Name , UnitProperties_Owner =p.UnitProperties_Owner , UnitProperties_Tell =p.UnitProperties_Tell , UnitProperties_UnitId =p.UnitProperties_UnitId }).ToList(); var Balance = d.AccountBalance.Where(c => c.AccountBalance_UnitId == id).FirstOrDefault(); if(Balance !=null ) { if (Balance.AccountBalance_Amount > 0) item.Demand = Balance.AccountBalance_Amount; else item.Debt = Balance.AccountBalance_Amount; } d.Dispose(); return View(item); } else { d.Dispose(); return View(); } } else { return View(); } } catch (Exception) { return View(); } }
شما کافیست برای action که برای دریافت در نظر گرفتید یک ورودی از نوع list و از آستم های ارسالی در نظر بگیرید
اینجوری وقتی ثبت رو میزنید کل لین به سمت action ارسال خواهد شد
به نمونه زیر دقت کنید
Model
public class EmployeeModelClass { public string Name { get; set; } public string Address { get; set; } public string Contact { get; set; } public IEnumerable<DepartmentModelClass> DeptList { get; set; } } public class DepartmentModelClass { public string DepartmentCode { get; set; } public string DepartmentName { get; set; } }
action
public class EmployeeController : Controller { // // GET: /Employee/ public ActionResult Index() { return View(new EmployeeModelClass()); } [HttpPost] public ActionResult Index(EmployeeModelClass emp, IEnumerable<DepartmentModelClass> dept) { emp.DeptList = dept; return View(emp); } }
View
Emp Name @Html.TextBox("Name",Model.Name) <br/> Address @Html.TextBox("Address",Model.Address) <br/> Contact @Html.TextBox("Contact",Model.Contact) <br/> <table> <tr> <th>Dept Code</th> <th>Dept Name</th> </tr> @{ for (int i = 0; i < 4; i++) { <tr> <td> @Html.TextBox("["+ i +"].DepartmentCode") </td> <td> @Html.TextBox("["+ i +"].DepartmentName")</td> </tr> } } </table> <input type="submit" value="Submit"/>
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)