我尝试连接两个表并显示那些已连接结果的表格,以及显示相同视图的创建表格
我刚跟着following questions回答
这些是我的模型类
<script language="JavaScript">
function toggle() {
if($("#check-buton").prop("checked") == true){
$('.chkall').prop('checked', true);
}else{
$('.chkall').prop('checked', false);
}
}
$('#industry').click(function(){
if($('#s').val().trim())
{
window.location.href= '<?php echo base_url();?>search?industry_id='+$('#industry_id').val().trim()
}else{
$('#alert_error').text('Please Select Industry').show();
return false;
}
});
</script>
<div class="loginAccount">
<form method="post" name="search" action="<?php echo base_url();?>search">
<h3>Search by Industry :</h3>
Select All: <input type="checkbox" name="industry_id[]" id="check-buton" value="" onclick="toggle()">
<ul class="searchbyindustry">
<?php
if($Industries)
{?>
<?php
foreach($Industries as $Industry)
{
?>
<li> <input type="checkbox" name="industry_id[]" class="chkall" value="<?php echo $Industry['id'];?>"> <?php echo $Industry['industry_name'];?>
</li> <?php
} }
?>
<br/>
<br/>
<!-- <button type="button" id="industry">Search</button>-->
<input type="submit" name="submit" value="Search">
</ul>
</form>
<?php
if(_inputPost('industry_id'))
{
$ind=implode(',', _inputPost('industry_id'));
//print($ind);die;
$ind=ltrim($ind,',');
$industry_id = $ind;
$flag = true;
$condition = ' and sector in ('.$ind.')';
$extraparams = '?industry_id='.$industry_id;
}else if(_inputGet('industry_id'))
{
$ind= _inputGet('industry_id');
//print($ind);die;
$ind=ltrim($ind,',');
$industry_id = $ind;
$flag = true;
$condition = ' and sector in ('.$ind.')';
$extraparams = '?industry_id='.$industry_id;
}
else if(trim(_inputGet('s')))
{
$s = trim(_inputGet('s'));
$flag = true;
$condition = ' and (name LIKE '.$this->db->escape('%'.$s.'%').' or mobile_office LIKE '.$this->db->escape('%'.$s.'%').' or mobile2 LIKE '.$this->db->escape('%'.$s.'%').' or email2 LIKE '.$this->db->escape('%'.$s.'%').")";
$extraparams = '?s='.$s;
}
这些是控制器方法
加入LINQ查询以获取列表
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; }
}
这是创建控制器方法
[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);
这是列表视图&#34; ProductCategory_List&#34;
[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);
}
这是我试图显示列表视图和创建视图的页面
@model IEnumerable<project_name.Models.AB_ProductTypeCategory>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ProductCategoryID)
</th>
...