I want to render the blog data (blog description and blog type) inside the index view? but how?
I am getting the error only one model class supported in the index view how to solve this issue
I want to render the blog view , after table tag end and before starting BlogCreate.
student.cs
- namespace DemoFFI.Models
- {
- public class student
- {
- [Key]
- public int studid { get; set; }
- [Required(ErrorMessage = "please enter the first name")]
- public string firstname { get; set; }
- [Required(ErrorMessage = "please enter the last name")]
- public string lastname { get; set; }
- [Required(ErrorMessage = "please enter the user name")]
- public string username { get; set; }
- [Required(ErrorMessage = "please enter the password")]
- public string password { get; set; }
- [Required(ErrorMessage = "please enter the email")]
- public string email { get; set; }
- }
- public class blog
- {
- [Key]
- public int blogid { get; set; }
- [Required(ErrorMessage = "please enter the blogdescription")]
- public string blogdescription { get; set; }
- [Required(ErrorMessage = "please select the blog type")]
- public string blogtype { get; set; }
- }
- }
HomeController.cs
- public class HomeController : Controller
- {
- private readonly dbcontextstudent dbstud;
- public HomeController()
- {
- dbstud = new dbcontextstudent();
- }
- public ActionResult Index(student stud)
- {
- var list = dbstud.stud.ToList();
- return View(list);
- }
- public ActionResult BlogCreate()
- {
- return View();
- }
- [HttpPost]
- public ActionResult BlogCreate(blog blg)
- {
- var blogcreate = dbstud.blog.Add(blg);
- dbstud.SaveChanges();
- return View(blogcreate);
- }
- }
Index.cshtml
- @model IEnumerable
- @{
- ViewBag.Title = "Index";
- }
Index
- @Html.ActionLink("Create New", "Create")
class="table">
- @Html.DisplayNameFor(model => model.firstname)
- @Html.DisplayNameFor(model => model.lastname)
- @Html.DisplayNameFor(model => model.username)
- @Html.DisplayNameFor(model => model.password)
- @Html.DisplayNameFor(model => model.email)
- @foreach (var item in Model)
- {
- @Html.DisplayFor(modelItem => item.firstname)
- @Html.DisplayFor(modelItem => item.lastname)
- @Html.DisplayFor(modelItem => item.username)
- @Html.DisplayFor(modelItem => item.password)
- @Html.DisplayFor(modelItem => item.email)
- @Html.ActionLink("Edit", "Edit", new { id = item.studid })
- }
- @{ Html.RenderAction("BlogCreate", "Home"); } //here I am creating the blog
BlogCreate.cshtml
- @model DemoFFI.Models.blog
- @{
- ViewBag.Title = "BlogCreate";
- }
BlogCreate
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- class="form-horizontal">
blog
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
class="form-group">- @Html.LabelFor(model => model.blogdescription, htmlAttributes: new { @class = "control-label col-md-2" })
class="col-md-10">- @Html.EditorFor(model => model.blogdescription, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.blogdescription, "", new { @class = "text-danger" })
class="form-group">- @Html.LabelFor(model => model.blogtype, htmlAttributes: new { @class = "control-label col-md-2" })
class="col-md-10">- @Html.DropDownListFor(x => x.blogtype, new List
- {
- new SelectListItem() {Text = "public", Value="public"},
- new SelectListItem() {Text = "private", Value="private"},
- })
- @*@Html.EditorFor(model => model.blogtype, new { htmlAttributes = new { @class = "form-control" } })*@
- @Html.ValidationMessageFor(model => model.blogtype, "", new { @class = "text-danger" })
class="form-group">class="col-md-offset-2 col-md-10">- "submit" value="Create" class="btn btn-default" />
- }
I am trying a pass a blog model inside the index view but I get an error:
Line 1: @model IEnumerable
Line 2: @model IEnumerable
Line 3:
Line 4: @{
Parser Error Message: Only one 'model' statement is allowed in a file.
see reference:
How to render the blogdata (blogdescription and blogtype) inside the index view??
please help?
I am try this issue to solve last 1 day but still issue not solved?

rahul patil159 reputationPosted Jun 7, 2020, 4:40 AM EDT
Index
Blog Data
Salman BegRank #284 · 8.8K reputationPosted Jun 7, 2020, 4:54 AM EDT
rahul patil159 reputationPosted Jun 7, 2020, 10:28 PM EDT
BlogCreate
blog
Blog Data
Index
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 10:43 PM EDT
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 3:19 AM EDT
Salman BegRank #284 · 8.8K reputationPosted Jun 7, 2020, 3:29 AM EDT
Salman BegRank #284 · 8.8K reputationPosted Jun 7, 2020, 8:50 PM EDT
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 9:02 PM EDT
rahul patil159 reputationPosted Jun 7, 2020, 9:16 PM EDT
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 9:26 PM EDT
rahul patil159 reputationPosted Jun 7, 2020, 9:34 PM EDT
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 9:49 PM EDT
rahul patil159 reputationPosted Jun 7, 2020, 9:54 PM EDT
rahul patil159 reputationPosted Jun 7, 2020, 9:58 PM EDT
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 9:59 PM EDT
rahul patil159 reputationPosted Jun 7, 2020, 10:09 PM EDT
Arvind KushwahaRank #685 · 3.5K reputationPosted Jun 7, 2020, 10:17 PM EDT