Note that there are some explanatory texts on larger screens.

plurals
  1. POMy "Create" View in my "Index" View, is it possible?
    primarykey
    data
    text
    <p>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 ?</p> <p>Thanks for your advices </p> <p><em><strong></em>___</strong><em>EDIT</em><strong>__</strong></p> <p>Controller : </p> <pre><code> 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); } </code></pre> <p>My _Create partial view :</p> <pre><code>@model MyProject.Models.Post &lt;h2&gt;Create&lt;/h2&gt; @using (Html.BeginForm()) { @Html.ValidationSummary(true) /**some stuff **/ } </code></pre> <p>my Index View :</p> <pre><code>@model IEnumerable&lt;MyProject.Models.Post&gt; @{ ViewBag.Title = "Index"; } &lt;p&gt; /** some stuff **/ &lt;/p&gt; @Html.Partial("_Create", **Here I can't declare model**) </code></pre> <p>And my Post Model :</p> <pre><code>public int PostId { get; set; } public int UserId { get; set; } public string Content { get; set; } </code></pre> <p>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‘. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload