Hi, I need to send in a bunch of form values to the create method (add new button) on the grid.
For edit, I used like this and it works fine.
grid call:
.Read(read => read.Action("Read_FinesByMLS", "FinesHistoryByMLS").Data("ParameterData"))
js function:
function ParameterData() {
alert("para=" + $("#MLSNumber").val());
return {
MLSNumber: $("#MLSNumber").val()
}
}
controller function:
public ActionResult Read_FinesByMLS([DataSourceRequest] DataSourceRequest request, string MLSNumber)
{
using (var context = new MATRIXEntities_Connection ())
{
IQueryable<FineHistory> finebymls = context.FineHistories;
if (MLSNumber != null)
{
finebymls = finebymls.Where(f => f.MLSNumber == MLSNumber); }
DataSourceResult result = finebymls.ToDataSourceResult(request, f => new FineHistoryViewModel
{
FineHistoryId = f.FineHistoryId ,
FineCode = f.FineCode,
});
return Json(result);
}
}
When I tried to do same for create, I am not getting any value for the parameter in the controller function. MLSNumber param is coming null. Any help is appreciated. Thanks
here is my create action call.
.Create(create => create.Action("Create_FinesByMLS", "FinesHistoryByMLS").Data("ParameterData"))
Its the same function call as above for edit function.
Controller function.
public ActionResult Create_FinesByMLS([DataSourceRequest] DataSourceRequest request, string MLSNumber) { using (var objFines_Context = new MATRIXEntities_Connection()) { */ //objFines_Context.usp_InsertFineHistory("211131297", "479", 4790, "713779DAF4844A", "239024", "281530", "kmantrip", "M"); //objFines_Context.SaveChanges(); } return View(); }the parameter is
@(Html.Kendo().Grid<KendoTest2.Models.DocumentType>() .Name("grid") .DataSource(dataSource => dataSource // Configure the grid data source .Ajax() // Specify that ajax binding is used .Read(read => read.Action("Products_Read", "Home")) // Set the action method which will return the data in JSON format ) .Columns(columns => { // Create a column bound to the ProductID property columns.Bound(product => product.Id); // Create a column bound to the ProductName property columns.Bound(product => product.Name); // Create a column bound to the UnitsInStock property }) .Pageable() // Enable paging .Sortable() // Enable sorting)public ActionResult Products_Read([DataSourceRequest]DataSourceRequest request) { using (var northwind = new MMCC_DocumentManagementEntities()) { IQueryable<DocumentType> products = northwind.DocumentTypes; DataSourceResult result = products.ToDataSourceResult(request); return Json(result); } }My grid column is:columns.Bound(r => r.RagStatus).EditorTemplateName("RAGStatus");Enum is:public enum RAGStatus{ Red = 1, Amber = 2, Green = 3,}public static List<SelectListItem> EnumToSelectList(Type enumType){ return Enum .GetValues(enumType) .Cast<int>() .Select(i => new SelectListItem { Value = i.ToString(), Text = Enum.GetName(enumType, i), } ) .ToList();}Enum template is:@model int@( Html.Kendo().DropDownListFor(m => m) .BindTo(EnumToSelectList(typeof(RAGStatus)).ToList()) .OptionLabel(optionLabel: "Please Select") .SelectedIndex(0))Here's what I've done so far:
I have the grid showing on my page and editable. I am able to send the values from the grid to the server with the form post (using a method similar to the one shown here: http://www.telerik.com/support/code-library/submit-form-containing-grid-along-with-other-input-elements)
I have looked at the custom editor examples here (http://demos.telerik.com/kendo-ui/web/grid/editing-custom.html) and here (http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/editor-templates) but this method involves creating a partial view for each dropdown. I would prefer not to have to copy/paste/edit this code every time I need a new dropdown. I think there should be a way to create a re-usable partial view that can perform this function. Along these lines, I have created a small view model and partial view like what is mentioned here (https://stackoverflow.com/questions/11498215/asp-net-mvc-built-in-support-for-dropdownlist-editor-template).
Current status:
The dropdown appears in my grid as expected, and I can select a value. I don't know how to get the text and value of the selected item so I can include them in the ClientTemplate, however.
@(Html.Kendo().Grid<AccountManagement.Business.ViewModels.Areas.DM.RehireDocumentSettingViewModel>() .Name("DocumentSettings") .Columns(columns => { /* columns.Bound(ds => ds.FormID) .ClientTemplate("#= FormID #" + "<input type='hidden' name='DocumentSettings[#= index(data)#].FormID' value='#= FormID #' />" ); */ columns.Bound(ds => ds.FormsViewModel) .ClientTemplate("#= 'test' #" + "<input type='hidden' name='DocumentSettings[#= index(data)#].FormID' value='#:data.Value #' />" ); columns.Bound(ds => ds.DocumentDateTypeName) .ClientTemplate("#= DocumentDateTypeName #" + "<input type='hidden' name='DocumentSettings[#= index(data)#].DocumentDateTypeName' value='#= DocumentDateTypeName #' />" ); columns.Bound(ds => ds.RemoveIfOlderThanDays) .ClientTemplate("#= RemoveIfOlderThanDays #" + "<input type='hidden' name='DocumentSettings[#= index(data)#].RemoveIfOlderThanDays' value='#= RemoveIfOlderThanDays #' />" ); columns.Command(command => command.Destroy()); } ) .ToolBar(toolbar => { toolbar.Create(); }) .Navigatable() .Sortable() .Scrollable() .Editable(editable => editable.Mode(GridEditMode.InCell)) .DataSource(dataSource => dataSource .Ajax() .Batch(true) .ServerOperation(false) .Events(events => events.Error("error_handler")) .Model(model => model.Id(ds => ds.FormID)) .Read("RehireDocumentSetting_Editing_Read", "RehireSetup") ) )public class DropDownViewModel { public string SelectedID { get; set; } public IEnumerable<SelectListItem> Items { get; set; } }@model AccountManagement.Business.ViewModels.Areas.DM.DropDownViewModel@(Html.Kendo().DropDownListFor(m => m) .DataValueField("Value") .DataTextField("Text") .BindTo(new SelectList(Model.Items, "Value", "Text", Model.SelectedID)) .Value("SelectedID"))