|
Dear Fellow developer. I am a newbie in MVC. Recently I try to perform the following:
//--- Model
public class Skill
{
public bool IsSkill { get; set; }
public string SkillStr { get; set; }
}
public class PageModel
{
public string UserName { get; set; }
public string Address { get; set; }
public List<skill> skills { get; set; }
}
//---Controller
public ViewResult UpdateSkills(int id)
{
PageModel model = GetPageModel(id);
model.skills = GetSkills(id);
return View(model);
}
[HttpPost]
public ActionResult UpdateSkills(PageModel model)
{
if (ModelState.IsValid)
{
List<string> SkillStr = new List<string>();
// ERROR: model.skills null
foreach (Skill rw in model.skills)
{
if (rw.IsSkill)
{
SkillStr.Add(rw.SkillStr);
}
}
}
// ... Other code are omitted
}
//--- View
@foreach(Skill rw in Model.skills)
{
@Html.EditorFor(m => rw.IsSkill) @Html.DisplayFor(m => rw.SkillStr) }
Now, the question that I am wondering is why the List<skill> skills become null when it returns from the view, while it was passed with value before the view is shown.
Does anyone have any clue what I am missing? I really can not figure out why.
Thank you for any enlightenment that you may provide.
|
|
|
|
|
well,I am very much a novice at this game. However, (and this may be wrong) your ListView info was passed to you via the server. You lost the connection (by Time-out),and your browser did not restore the page.This is both a good and bad thing.
Bram van Kampen
|
|
|
|
|
Thanks Bram,
I am quite confused actually.
When the Controller pass the data, the Username, Address and the list of skills are passed to the View properly. I can display them.
But when the view post to the Controller, the Username and Address is passed properly. But not the list of skill.
Do you have any idea on how to handle it? It is actually a header-detail type of data passed between View and Controller.
|
|
|
|