Click here to Skip to main content
15,922,696 members
Home / Discussions / Web Development
   

Web Development

 
QuestionMVC: Pass List<> between View and Controller Pin
astuserp11-Feb-13 23:05
astuserp11-Feb-13 23:05 
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.
AnswerRe: MVC: Pass List<> between View and Controller Pin
Bram van Kampen22-Feb-13 15:16
Bram van Kampen22-Feb-13 15:16 
GeneralRe: MVC: Pass List<> between View and Controller Pin
astuserp24-Feb-13 15:20
astuserp24-Feb-13 15:20 
Questionweb development Pin
Smart0035-Feb-13 1:30
professionalSmart0035-Feb-13 1:30 
AnswerRe: web development Pin
Richard MacCutchan5-Feb-13 1:35
mveRichard MacCutchan5-Feb-13 1:35 
QuestionRe: web development Pin
Smart0037-Feb-13 0:55
professionalSmart0037-Feb-13 0:55 
AnswerRe: web development Pin
Richard MacCutchan7-Feb-13 1:32
mveRichard MacCutchan7-Feb-13 1:32 
AnswerRe: web development Pin
Sandeep Mewara5-Feb-13 2:26
mveSandeep Mewara5-Feb-13 2:26 
Questionweb development Pin
Smart0037-Feb-13 0:51
professionalSmart0037-Feb-13 0:51 
AnswerRe: web development Pin
Sandeep Mewara8-Feb-13 3:56
mveSandeep Mewara8-Feb-13 3:56 
AnswerRe: web development Pin
Rahul Rajat Singh5-Feb-13 19:21
professionalRahul Rajat Singh5-Feb-13 19:21 
Questionweb development Pin
Smart0037-Feb-13 0:53
professionalSmart0037-Feb-13 0:53 
AnswerRe: web development Pin
Rahul Rajat Singh7-Feb-13 17:35
professionalRahul Rajat Singh7-Feb-13 17:35 
Generalweb development Pin
Smart0038-Feb-13 0:39
professionalSmart0038-Feb-13 0:39 
QuestionDynamic Website Deployment in IIS 6 Pin
dihnekhs_gr4-Feb-13 3:07
dihnekhs_gr4-Feb-13 3:07 
QuestionExport to excel Pin
Balaji Bethala3-Feb-13 23:03
Balaji Bethala3-Feb-13 23:03 
QuestionDataSet Pin
Abdulla_M3-Feb-13 21:01
Abdulla_M3-Feb-13 21:01 
AnswerRe: DataSet Pin
Sandeep Mewara3-Feb-13 21:38
mveSandeep Mewara3-Feb-13 21:38 
GeneralRe: DataSet Pin
Abdulla_M3-Feb-13 23:02
Abdulla_M3-Feb-13 23:02 
QuestionHow to Approach Real Time Updates with Web Services Pin
Richard Andrew x642-Feb-13 17:56
professionalRichard Andrew x642-Feb-13 17:56 
AnswerRe: How to Approach Real Time Updates with Web Services Pin
SoMad12-Feb-13 1:36
professionalSoMad12-Feb-13 1:36 
GeneralRe: How to Approach Real Time Updates with Web Services Pin
Richard Andrew x6412-Feb-13 7:21
professionalRichard Andrew x6412-Feb-13 7:21 
QuestionI am developing a GPS tracking app on Android .but i want to make web server which take update from cell using GPS. Pin
babarkhalid1-Feb-13 21:00
babarkhalid1-Feb-13 21:00 
AnswerRe: I am developing a GPS tracking app on Android .but i want to make web server which take update from cell using GPS. Pin
Richard MacCutchan1-Feb-13 23:06
mveRichard MacCutchan1-Feb-13 23:06 
GeneralRe: I am developing a GPS tracking app on Android .but i want to make web server which take update from cell using GPS. Pin
babarkhalid1-Feb-13 23:10
babarkhalid1-Feb-13 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.