I'm inserting data from one (model)table to another, but it is passing null values.
Here is the code for the controller :
public ActionResult PendingBlogs()
{
OMSDataContext db = new OMSDataContext();
var query = from a in db.BlogApprovals
select a;
return View(query);
}
[HttpPost]
public ActionResult PendingBlogs(BlogApproval blogap)
{
OMSDataContext db = new OMSDataContext();
Blog b = new Blog
{
BlogTitle = blogap.BlogTitle1,
BlogContent = blogap.BlogContent1,
UserName = blogap.UserName1,
Date = blogap.Date1,
IsApproved = true
};
db.Blogs.InsertOnSubmit(b);
db.SubmitChanges();
return RedirectToAction("Index");
}
And here is my View code :
@model IEnumerable<MVCDemo.Models.BlogApproval>
@{
ViewBag.Title = "PendingBlogs";
}
<h2>PendingBlogs</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.BlogTitle1)
</th>
<th>
@Html.DisplayNameFor(model => model.BlogContent1)
</th>
<th>
@Html.DisplayNameFor(model => model.UserName1)
</th>
<th>
@Html.DisplayNameFor(model => model.Date1)
</th>
<th>
@Html.DisplayNameFor(model => model.IsApproved1)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.BlogTitle1)
</td>
<td>
@Html.DisplayFor(modelItem => item.BlogContent1)
</td>
<td>
@Html.DisplayFor(modelItem => item.UserName1)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date1)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsApproved1)
</td>
<td>
<form asp-controller="Admin" method="post">
<input type="submit" name="answer" value="RunRegisterdJob" />
</form>
</td>
</tr>
}
</table>
The two models (Blog and BlogApproval) are tables in the models folder. BlogApproval has data inside it, but it's not returning the data from the table for some reason.
I've looked at this thread, and have renamed the columns in the BlogApproval table so that they are different from the columns on the Blog table, but that didn't fix it.