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

[Solved] ForeingKey Column Grid MVC - Razor

0 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
JORGE
Top achievements
Rank 1
JORGE asked on 10 Oct 2012, 10:13 PM
Hallo every on

I´m can´t to use o ForeingKey Column, What I´m miss. I now almost there.
Thanks A lot.


That Is I have:

// View:

@(Html.Telerik().Grid(Model)

.Name(

 

"Grid")

 

.Localizable(

 

"pt-BR")

 

.DataKeys(keys =>

{

keys.Add(c => c.USR_CD);

})

.ToolBar(commands => commands.Insert().ButtonType(type)

.ImageHtmlAttributes(

 

new { style = "margin-left:0" }))

 

.DataBinding(databinding =>

{

databinding.Server()

.Select(

 

"Index", "Usuarios")

 

.Update(

 

"Edit", "Usuarios")

 

.Delete(

 

"Delete", "Usuarios")

 

.Insert(

 

"Create", "Usuarios");

 

 

})

 

.Columns(c =>

{

c.Bound(o => o.USR_CD).Width(60).Title(

 

"Código");

 

c.Bound(o => o.USR_NOME).Width(300).Title(

 

"Nome");

 

c.Bound(o => o.USR_LOGIN).Width(300).Title(

 

"Login");

 

 

 

//c.Bound(o => o.USR_UF).Width(100).Title("UF");

 

c.ForeignKey(o => o.USR_UF, ViewBag.UF

 

as SelectList).Width(100);

 

c.Bound(o => o.USR_STATUS).Width(100).Title(

 

"Status");

 

c.Command(cmd =>

{

cmd.Edit().ButtonType(type);

cmd.Delete().ButtonType(type);

}).Width(180).Title(

 

"Altera/Deleta");

 

})

.Editable(editing => editing.Mode(mode))

.Pageable(paging => paging.PageSize(10))

.Sortable()

.Footer(

 

true)

 

.NoRecordsTemplate(

 

"Sem Registro")

 

.Resizable(resizing => resizing.Columns(

 

true))

 

.Filterable(filtering => filtering.Enabled(

 

true))

 

.Groupable(grouping => grouping.Enabled(

 

false))

 

.HtmlAttributes(

 

new { style = " font-family:arial; font-size: .9em; font-weight: bold;" })

 

)

//Controller

 

using

 

 

System;

 

 

 

 

using

 

 

System.Collections.Generic;

 

 

 

 

using

 

 

System.Data;

 

 

 

 

using

 

 

System.Data.Entity;

 

 

 

 

using

 

 

System.Linq;

 

 

 

 

using

 

 

System.Web;

 

 

 

 

using

 

 

System.Web.Mvc;

 

 

 

 

using

 

 

STC_WEB.Models;

 

 

 

 

using

 

 

Telerik.Web.Mvc;

 

 

 

 

namespace

 

 

STC_WEB.Controllers

 

{

 

 

public class UsuariosController : Controller

 

 

 

 

 

{

 

 

private AGRELENSEEntities db = new AGRELENSEEntities();

 

 

 

//

 

 

 

 

 

 

 

 

public ViewResult Index()

 

{

 

 

var ESTADO = db.SYS_UF.AsQueryable();

 

ViewBag.UF =

 

new SelectList(ESTADO.ToList(), "SYS_UF_CD", "SYS_UF_CD");

 

 

 

return View(db.USR_USUARIOS.ToList());

 

 

}

 

 

//

 

 

 

 


\\Model

 

using

 

 

System;

 

 

 

 

using

 

 

System.Collections.Generic;

 

 

 

 

using

 

 

System.ComponentModel.DataAnnotations;

 

 

 

 

namespace

 

 

STC_WEB.Models

 

{

 

 

public partial class USR_USUARIOS

 

 

 

 

 

{

 

 

public USR_USUARIOS()

 

{

 

 

this.CLI_CLIENTES = new HashSet<CLI_CLIENTES>();

 

 

 

this.CON_CTRC = new HashSet<CON_CTRC>();

 

 

 

this.CTR_CTRB = new HashSet<CTR_CTRB>();

 

 

 

this.MOT_MOTORISTAS = new HashSet<MOT_MOTORISTAS>();

 

 

 

this.NTC_NOTAFCON = new HashSet<NTC_NOTAFCON>();

 

 

 

this.NTS_NOTASERV = new HashSet<NTS_NOTASERV>();

 

 

 

this.SYS_LOG = new HashSet<SYS_LOG>();

 

 

 

this.SYS_USR_CONFIGURACAO = new HashSet<SYS_USR_CONFIGURACAO>();

 

 

 

this.TAB_TABECLI = new HashSet<TAB_TABECLI>();

 

 

 

this.TMV_MARVEICULO = new HashSet<TMV_MARVEICULO>();

 

 

 

this.VEI_VEICULOS = new HashSet<VEI_VEICULOS>();

 

}

 

 

 

public int USR_CD { get; set; }

 

 

 

public string USR_LOGIN { get; set; }

 

 

 

public string USR_PASSWORD { get; set; }

 

 

 

public string USR_NOME { get; set; }

 

 

 

 

//[UIHint("USR_UF"), Required]

 

 

 

 

 

 

 

//public SYS_UF SYS_UF_CD { get; set; }

 

 

 

 

 

 

 

 

public string USR_UF { get; set; }

 

 

 

public string USR_CONTATOEMAIL { get; set; }

 

 

 

public bool USR_STATUS { get; set; }

 

 

 

 

public virtual ICollection<CLI_CLIENTES> CLI_CLIENTES { get; set; }

 

 

 

public virtual ICollection<CON_CTRC> CON_CTRC { get; set; }

 

 

 

public virtual ICollection<CTR_CTRB> CTR_CTRB { get; set; }

 

 

 

public virtual ICollection<MOT_MOTORISTAS> MOT_MOTORISTAS { get; set; }

 

 

 

public virtual ICollection<NTC_NOTAFCON> NTC_NOTAFCON { get; set; }

 

 

 

public virtual ICollection<NTS_NOTASERV> NTS_NOTASERV { get; set; }

 

 

 

public virtual ICollection<SYS_LOG> SYS_LOG { get; set; }

 

 

 

public virtual ICollection<SYS_USR_CONFIGURACAO> SYS_USR_CONFIGURACAO { get; set; }

 

 

 

public virtual ICollection<TAB_TABECLI> TAB_TABECLI { get; set; }

 

 

 

public virtual ICollection<TMV_MARVEICULO> TMV_MARVEICULO { get; set; }

 

 

 

public virtual ICollection<VEI_VEICULOS> VEI_VEICULOS { get; set; }

 

 

 

public virtual ACE_ACESSOS ACE_ACESSOS { get; set; }

 

 

 

internal static object All()

 

{

 

 

throw new NotImplementedException();

 

}

}

 

}

Tags
General Discussions
Asked by
JORGE
Top achievements
Rank 1
Share this question
or