i’ve a table
post(p_id,u_id(FK),date,title,type,viewer)
and a Modelclass UserModel.cs with(p_id,u_id,date,title,type). When i to create a new post in a post controller i tried like
public ActionResult Create(PostModel p)
{
if (ModelState.IsValid)
{
p.date = DateTime.Today;
post post = new Models.DB.post();
post.u_id = User.Identity.Name;
post.date = p.date;
post.title = p.title;
post.type= p.type;
post.viwer=1;
try{ db.posts.AddObject(post);
db.SaveChanges();
return RedirectToAction("LoggedIndex");
}
catch{ return RedirectToAction("Index"); }
}
return View(p);
}
It is not Working. I think from is not submitting when i submit always view is returned. i i’ve created stronly typed create view. in create.cshtml i’ve two hidden field user_id and date of postModel Object. I’m very new at MVC.please help me thanks in advance….
Sending Data from View to the Controler by using the MVC-Model
I understand it like that: you have a mvc3 page and want to send some custom data to your controller:
Controller:
View:
Further informations: http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx