This is a migrated thread and some comments may be shown as answers.

Custom popup editor problem

4 Answers 522 Views
Grid
This is a migrated thread and some comments may be shown as answers.
license
Top achievements
Rank 1
license asked on 17 Dec 2012, 10:15 AM
Hi,
We use MVC 4 and EF 4.5.
I have grid with " .Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("Company"))".
My EditorTemplate looks like this:

...
 <div class="editor-label">
        @Html.LabelFor(model => model.CompanyUrl)
    </div>
    <div class="editor-field">
        @Html.DisplayFor(model => model.CompanyUrl)
    </div>
 
    <div class="editor-label">
        @Html.LabelFor(model => model.FirstName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.FirstName)
        @Html.ValidationMessageFor(model => model.FirstName)
    </div>
...
I want the field "CompanyUrl" to be readonly and for that I call "DisplayFor" but when I click for editing DisplayFor shows
nothing. 

When I'm using GridEditMode.InLine and  m.Field(f => f.CompanyUrl).DefaultValue(string.Empty).Editable(false); everything is OK. I want to use popup because my class has too many fields and  default popup editor shows too many unwanted fields.
Am I doing something wrong ?
Thanks

P.S One more thing. I want a field edited with kendo editor to be shown formatted in the grid column, not like now "<p>Some Text</p><p><strong>New Line</strong></p>
".
The column is in  " .ClientDetailTemplateId("clientCommentsTemplate")" 

4 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 17 Dec 2012, 11:48 PM
I'm having the same issue.

Below is my Custom Popup

@model RenewalMemberViewModel
            
@Html.HiddenFor( model => model.MembershipNumber )
 
<div class="editor-label">
    @Html.LabelFor( model => model.Name )
</div>
<div class="editor-field">
    @Html.DisplayFor(model => model.Name )
</div>
<div class="editor-label">
    @Html.LabelFor( model => model.MembershipNumber )
</div>
<div class="editor-field">
    @Html.DisplayFor( model => model.MembershipNumber )
</div>
<div class="editor-label">
    @Html.LabelFor( model => model.MembershipType )
</div>
<div class="editor-field">
    @Html.EditorFor( model => model.MembershipType )
    @Html.ValidationMessageFor( model => model.MembershipType )
</div>
<div class="editor-label">
    @Html.LabelFor( model => model.ExpDate )
</div>
<div class="editor-field">
    @Html.DisplayFor( model => model.ExpDate )
</div>
None of the DisplayFor s work. If i replace them with EditorFor it properly displays a text box editor populated with the correct data but these fields are meant to be read only in this pop-up. Any help would be appreciated.
0
Daniel
Telerik team
answered on 19 Dec 2012, 08:19 AM
Hello,

The DisplayFor helper will not work when using Ajax binding because it just outputs the value and there is no way to determine that the value should be shown on the client. Instead, you should use text binding for the property e.g.

<div class="editor-label">
        @Html.LabelFor(model => model.CompanyUrl)
</div>
<div class="editor-field">
    <span data-bind="text: CompanyUrl"></span>
</div>
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sindhura
Top achievements
Rank 1
answered on 25 Aug 2015, 12:01 AM

Hi Daniel,

Is there a way I could get the value into a html variable of the popup editor template?

Something like this :
@{
var value = Model.Name; //get the value of Name in the model
}

Or is it possible to access this value using Javascript in editor template? For example:
<script>
var value = @Model.Name;  //get the value of Name in the model
</script>

Thanks in advance.

0
Daniel
Telerik team
answered on 26 Aug 2015, 01:35 PM
Hi,

No, it is not possible to access the value on the server if you are using Ajax binding for the grid. Accessing the value with the JavaScript code that you provided will also not work. You can access the value in the grid edit event.

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
license
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Daniel
Telerik team
Sindhura
Top achievements
Rank 1
Share this question
or