Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 19, 2012 01:57 AM by DhavalShah89
Member
13 Points
63 Posts
Aug 18, 2012 09:09 AM|LINK
I have a model as follow
public class BodyContentsModel { public TeamModel TeamModel { get; set; } }
I also have controller as follow
[ChildActionOnly] public ActionResult BodyContents() { TeamModel teamModel = new TeamModel(); var model = new BodyContentsModel() { TeamModel = teamModel }; return PartialView(model); } [HttpPost, ActionName("BodyContents")] public ActionResult Register(FormCollection model) { return RedirectToAction("Index", "Home"); }
I have BodyContent.cshtml as follow
<div> @Html.LabelFor(model => model.TeamModel.Name) </div> <div> <input value="Team Name" /><br /> </div> <p> <input type="submit" value="BodyContents" /> </p>
But I do not see any value in Register POST method.
Anything I missed?
I want to save the newly entered data by user. but i dnt see those values :(
Aug 18, 2012 09:12 AM|LINK
Issue resolved by adding
@Html.EditorFor(model => model.TeamModel.Name)
112 Points
79 Posts
Aug 19, 2012 01:57 AM|LINK
Probably you did not give id property to your <input> tag and hense nothing was shown in post.
You have used @Html.EditorFor() now have a look at its html you will see id property,which you will get in post in action.
cpms
Member
13 Points
63 Posts
Post does not contain form collection data :(
Aug 18, 2012 09:09 AM|LINK
I have a model as follow
public class BodyContentsModel { public TeamModel TeamModel { get; set; } }I also have controller as follow
[ChildActionOnly] public ActionResult BodyContents() { TeamModel teamModel = new TeamModel(); var model = new BodyContentsModel() { TeamModel = teamModel }; return PartialView(model); } [HttpPost, ActionName("BodyContents")] public ActionResult Register(FormCollection model) { return RedirectToAction("Index", "Home"); }I have BodyContent.cshtml as follow
<div> @Html.LabelFor(model => model.TeamModel.Name) </div> <div> <input value="Team Name" /><br /> </div> <p> <input type="submit" value="BodyContents" /> </p>But I do not see any value in Register POST method.
Anything I missed?
I want to save the newly entered data by user. but i dnt see those values :(
Deepu
cpms
Member
13 Points
63 Posts
Re: Post does not contain form collection data :(
Aug 18, 2012 09:12 AM|LINK
Issue resolved by adding
@Html.EditorFor(model => model.TeamModel.Name)
Deepu
DhavalShah89
Member
112 Points
79 Posts
Re: Post does not contain form collection data :(
Aug 19, 2012 01:57 AM|LINK
Probably you did not give id property to your <input> tag and hense nothing was shown in post.
You have used @Html.EditorFor() now have a look at its html you will see id property,which you will get in post in action.