开发者

ASP.NET MVC Edit problem - "entity" data from controller aren't passed to the view

开发者 https://www.devze.com 2023-01-13 00:39 出处:网络
I\'m pretty sure t开发者_运维知识库hat I complicated my question. Sorry, I didn\'t know how to express myself. Situation is next :

I'm pretty sure t开发者_运维知识库hat I complicated my question. Sorry, I didn't know how to express myself. Situation is next :

public ActionResult Edit(int id)
    {
        CreateTrainingModel editTrainingModel = new CreateTrainingModel();

        editTrainingModel.Training = training.GetByID(id);
        editTrainingModel.Player = player.GetAll();            

        return View(editTrainingModel);
    }

and Editor template for Html.EditorFor() :

@inherits System.Web.Mvc.WebViewPage<TrainingStatistics.Models.ViewModels.CreateTrainingModel>

@Html.ValidationSummary()

<table>
 @Html.HiddenFor(x => x.Training.TrainingID) 

 <tr>
  <td>Training Date</td>
  <td><input type="text" id="datepicker" name="Training.Date"></td>
  <td>@Html.ValidationMessageFor(x => x.Training.Date)</td>
 </tr> 

</table>

Problem is that when I want to edit this, data from model aren't passed to the view. I think that problem is because of using ViewModels and I'm doing something wrong here..When I try to update something which is consist of only one entity (example Player) and when I'm not using ViewModel everything is fine.

Thank you in advance!


I believe you need to create editor template for the view model. You can see the exmaples of this below http://www.codecapers.com/post/Display-and-Editor-Templates-in-ASPNET-MVC-2.aspx http://davidhayden.com/blog/dave/archive/2009/08/21/htmleditorforscaffoldcolumnattribute.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消