Hi!
Is it possible to pass additional data from my grid to the popup window beside the bound object?
@(Html.Kendo().Grid<GazoraAllasModels>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.Oraallas).Title("Óraállás");
columns.Bound(c => c.LeolvasasDatum).Title("Leolvasás dátuma");
})
.Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("AddOraallas").AdditionalViewData(new { maxOra = "=#MaxOra()#" }))
I would like to pass data of a return value of javascript function as you can see (MaxOra()
On the editable template cshtml file has @ViewData["maxOra"] but the value is the string of "=#MaxOra#" and not the value. The cshtml starts with these lines, so I cannot pass this value in model:
@model MyProject.Models.MyProjectModels
@using Kendo.Mvc.UI
@ViewData["maxOra"]
This value cannot be in the model class. I really need to pass it as additional data.
Thanks
5 Answers, 1 is accepted
Currently, the additional data can be passed only as static data.
@{
string
customValue=
"some value"
;
}
.AdditionalViewData(
new
{customValue= customValue})
The other option will be to use the document ready event of the Custom template used for editing to execute a function which will be called every time the template is used:
<script>
$(document).ready(
function
() {
var
uid = $(
"#@ChildGridName"
).closest(
"[data-uid]"
).data(
"uid"
);
var
parentGrid = $(
"#@ViewData["
GridName
"]"
).data(
"kendoGrid"
);
var
model = parentGrid.dataSource.getByUid(uid);
console.log(model)
});
</script>
I hope this is helpful.
Regards,
Stefan
Progress Telerik
Hi Stefan,
I have the same problem but I can not solve it by your example.
I need to get the ID of the record being used in the Edit Template.
In this Template I'm using @Html.HiddenFor(b => b.UserID) but I also could not get the value for it.
See part of my code:
@(Html.Kendo().Grid<Site.Models.BullViewModel>()
.Name("grid")
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.DisplayDeleteConfirmation(false)
.TemplateName("BullEdit").Window(w => w.Title("Bull")))
The UserID value should be available directly inside the template.
Please refer to the following project demonstrating how to set up the editors inside the template when a custom popup editor is used inside the Grid:
https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/custom-popup-editor
If the issue still occurs please provide an example reproducing it as this will allow providing a suggestion best suited for it.
Regards,
Stefan
Progress Telerik
Hi Stefan,
I'll try to explain the situation in more detail.
I have a grid that is a list of bulls, when the bull is clicked, a popup with the bull data opens.
So far so good, bull data is being sent to "EditorTemplates" without any problems. All controls are populated with model data.
This popup has the control "Html.Kendo (). TabStrip ()", in tab 1 are all the data of the model, and in tab 2 it must be populated with data that is not in this model.
My idea is to populate these other data using jquery, and when the user is "saving" the changes I save these two types of data separately.
The problem is that I am not able to "get" the UserID that is used in a hidden control, as shown below.
@Html.HiddenFor (b => b.UserID)
This object is created with the name "UserID";
But when I try to "catch" this value, it is always null.
Any suggestions on how to solve this situation or how to "read" the value of this control?
Could you please elaborate if the UserID is part of the Grid model, because if it is part from the edited dataItem, its value should be set to the hidden input element when the editor template is bound?
If the issue persists you could open support ticket and attach a runnable project demonstrating the scenario and the issue, so we can test and debug it locally.
Regards,
Konstantin Dikov
Progress Telerik