I'am using ASP.NET MVC 4 with EF, I have a PostController with the Index and Create views. I would like to have both on the same page for adding a post, and visualize it on the same page. How can I do it ?
Thanks for your advices
___EDIT__
Controller :
public ActionResult Index()
{
return View(db.Posts.ToList());
}
[HttpGet]
public ActionResult Create()
{
return PartialView("_Create", **Here I can't declare model**);
}
[HttpPost]
public ActionResult Create(FormCollection values)
{
var post = new Post();
TryUpdateModel(post);
if (ModelState.IsValid)
{
/** somme code **/
db.Posts.Add(post);
db.SaveChanges();
return RedirectToAction("Index");
}
return View("_Create", post);
}
My _Create partial view :
@model MyProject.Models.Post
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
/**some stuff **/
}
my Index View :
@model IEnumerable<MyProject.Models.Post>
@{
ViewBag.Title = "Index";
}
<p>
/** some stuff **/
</p>
@Html.Partial("_Create", **Here I can't declare model**)
And my Post Model :
public int PostId { get; set; }
public int UserId { get; set; }
public string Content { get; set; }
It tells me that "The model item passed into the dictionary is of type ‘System.Collections.Generic.List`1[MyProject.Models.Post]’ but this dictionary requires a model item of type ‘MyProject.Models.Post‘.