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?
Arvind KushwahaPosted Jun 8, 2020, 2:43 AM
rahul patilPosted Jun 8, 2020, 2:28 AM
BlogCreate
blog
Blog Data
Index
Arvind KushwahaPosted Jun 8, 2020, 2:17 AM
rahul patilPosted Jun 8, 2020, 2:09 AM
Arvind KushwahaPosted Jun 8, 2020, 1:59 AM
rahul patilPosted Jun 8, 2020, 1:58 AM
rahul patilPosted Jun 8, 2020, 1:54 AM
Arvind KushwahaPosted Jun 8, 2020, 1:49 AM
rahul patilPosted Jun 8, 2020, 1:34 AM
Arvind KushwahaPosted Jun 8, 2020, 1:26 AM
rahul patilPosted Jun 8, 2020, 1:16 AM
Arvind KushwahaPosted Jun 8, 2020, 1:02 AM
Salman BegPosted Jun 8, 2020, 12:50 AM
Salman BegPosted Jun 7, 2020, 8:54 AM
rahul patilPosted Jun 7, 2020, 8:40 AM
Index
Blog Data
Salman BegPosted Jun 7, 2020, 7:29 AM
Arvind KushwahaPosted Jun 7, 2020, 7:19 AM