2014-02-22 3 views
0

Я использую шаблон редактора для редактирования записи. Но I добавить столбец внешнего ключа в связанных полях, Добавить новую кнопку перестает работать, но правильно отредактируйте работу. Вот мой код.kendo grid Добавить новую запись не работает

@(Html.Kendo().Grid<TelerikMvcTestApp.Models.VM.ReferralViewModel>() 
    .Name("grid") 
    .Columns(c => 
    { 
     c.Bound(i => i.ReferralDate).Title("Date"); 
     c.ForeignKey("AssignedMD.ID", (SelectList)ViewData["UserList"]).Title("Assigned MD").Width(200); // When I comment this line, then It works fine 
c.Command(cmd => 
     { 
      cmd.Edit(); 
      cmd.Destroy(); 
     }); 

    }) 
    .HtmlAttributes(new { style = "height: 500px;" }) 
    .Scrollable() 
    .Groupable() 
    .Sortable() 
    .ToolBar(tb => tb.Create()) 
      .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("ReferralEdit")) 
    .Pageable(pageable => pageable 
     .Refresh(true) 
     .PageSizes(true) 
     .ButtonCount(5)) 
    .DataSource(dataSource => 
     dataSource 
     .Ajax() 
     .ServerOperation(true) 
     .PageSize(10) 
     .Model(model => 
     { 
      model.Id(i => i.ID); 
      model.Field(i => i.ID).Editable(false); 
      model.Field(i => i.AssignedMD.ID).DefaultValue(1); 
     }) 
     .Create(i => i.Action("ReferralCreate", "Referral")) 
     .Read(i => i.Action("ReferralRead", "Referral")) 
     .Update(i => i.Action("ReferralUpdate", "Referral").Type(HttpVerbs.Post)) 
     .Destroy(i => i.Action("ReferralDelete", "Referral")) 

Когда я закомментировать эту строку, то он работает отлично c.ForeignKey("AssignedMD.ID", (SelectList)ViewData["UserList"]).Title("Assigned MD").Width(200);

ответ

0

Вам нужно сделать редактор в столбце сетки, связанный.не Foregin ключевой столбец в этом столбце только для чтения и не будет отправлять обратно значение выбора DropDownList к функции создания в вас контроллер

** * ** * ** * * * * ** *Сетка Модель ** * ** * ** * ** * ** * *

public Class ReferralViewModel{ 

public DateTime UserEditorModel {get; set;} 

//along with other grid mode 
public UserEditorModel User {get; set;} 

} 
public Class UserEditorModel 
{ 
    public int UserId {get; set;} 
    public string UserName {get; set;} 

} 

** * ** * ** * ** * ** * ** * * Grid * * ** * ** * ** * ** * ****

.Columns(c => 
    { 
     c.Bound(i => i.ReferralDate).Title("Date"); 
      c.Bound(i=>i.User).EditorTemplateName("UserListEditor") 
      .ClientTemplate("#=User.UserName#"); 
    } 

c.Command(cmd => { 
      cmd.Edit(); 
      cmd.Destroy(); 
     }); 

    }) 

** * ** * ** * *Редактор* ** * ** * ** * **

@(Html.Kendo().DropDownList() 
    .Name("User") // Name of the widget should be the same as the name of the property  
    .DataValueField("UserId") 
    .DataTextField("UserName")  
    .BindTo(ViewBag.UserList) 
) 

** * ** * ** * ** * ** Создать метод * ** * ** * ** * ****

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ReferralViewModel Model) 
{ 
     //e.g 
     var userId=Model.User.UserId; 

} 

С уважением Шахзад

Смежные вопросы