Im trying to join two tables and show a table from those joined results , as well as show a create form the same view
I just followed following questions answer
here these are the my model classes
public class CategoryViewModel
{
public AB_ProductTypeCategory categoryCreate { get; set; }
public IEnumerable<AB_ProductTypeCategory> categoryList { get; set; }
}
public partial class AB_ProductTypeCategory
{
public string ProductCategoryID { get; set; }
public string ProductTypeID { get; set; }
public string ProductCategoryNameEn { get; set; }
}
these are the controller methods
Join LINQ query to get the list
[HttpGet]
public ViewResult ProductCategory_List()
{
var catagorylist = from cat in db.AB_ProductTypeCategory
join typ in db.AB_ProductType on cat.ProductTypeID equals typ.ProductTypeID
select new AB_ProductTypeCategory
{
ProductCategoryID = cat.ProductCategoryID,
ProductCategoryNameEn = cat.ProductCategoryNameEn,
ProductTypeID= typ.ProductTypeID,
};
return View(catagorylist);
this is create controller method
[HttpGet]
public ActionResult ProductCategory_Create()
{
Product_Type_DropDownListEn();
Product_Type_DropDownListAr();
return View();
}
[HttpPost]
public ActionResult ProductCategory_Create(AB_ProductTypeCategory product_category)
{
Product_Type_DropDownListEn(product_category.ProductTypeID);
Product_Type_DropDownListAr(product_category.ProductTypeID);
if (ModelState.IsValid)
{
..
}
return View(product_category);
}
this is List viewpage "ProductCategory_List"
@model IEnumerable<project_name.Models.AB_ProductTypeCategory>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ProductCategoryID)
</th>
...
this is page Im trying to show list view and create view
@model project_name.Models.AB_ProductTypeCategory
@{
}
@{Html.RenderAction("ProductCategory_List", "Home");}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Create New Product Category</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.ProductCategoryID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProductCategoryID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProductCategoryID, "", new { @class = "text-danger" })
</div>
</div>
.....