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

[Solved] Telerik-MVC Grid Display value of property versus edit value

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard
Top achievements
Rank 1
Richard asked on 27 Aug 2011, 02:14 AM

Hopefully this will have a simple answer.

Using MVC3, I am passing a simple list of POCO objects as a model to my view:


<pre><code>public partial class PeopleAddress
{
    public int Id { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
    public int PersonId { get; set; }
 
    public virtual Person Person { get; set; }
}</code></pre>


I use the PeopleId as the FK property to the Person entity, and the Person navigational property to navigate to the object. Here is my controller for the view:

<pre><code>public ViewResult Index()
    {
        var peopleaddresses = db.PeopleAddresses.Include("Person");
        return View(peopleaddresses.ToList());
    }</code></pre>


Pretty trivial. I add the columns to the grid and normal edit modes, etc in the view, but for the PersonId property.

QUESTION ABOUT COLUMNS: How can I get the select (normal) mode to display the model.Person.Name, but keep the edit mode on editing model.PersonId? For model binding purposes, I need the HTTP post to send PersonId.

Help!

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 29 Aug 2011, 09:27 AM
Hello Richard,

 You can create a bound column that has its template set to display the person name. Something like this:

columns.Bound(p => p.PersonId).Template(p =>
{
>%
     <%= p.Person.Name %>
<%
}).ClientTemplate("<#= Person.Name #>");

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or