Contoller: [HttpGet]
public ActionResult postyourad()
{
return View(new masterList());
}
[HttpPost]
public ActionResult postyourad(masterList ddlListPostData)
return View(ddlListPostData);
View :
@model withoutModelEdmx.Models.masterList
@{
ViewBag.Title = "dropdownlist bind demo with model";
@using (Html.BeginForm("postyourad", "stok", FormMethod.Post, new { id = "TheForm" }))
@Html.DropDownListFor(x => x._brand, Model.getBrand(), "--Choose Your Brand--",
new
onchange = "document.getElementById('TheForm').submit();"
})
@Html.DropDownListFor(x => x._product, Model.getProduct(), "--Choose Your Product--",
@Html.DropDownListFor(x => x._model, Model.getModel(), "--Choose Your Model--",
} )
<input type="submit" value="submit" />
<table id="tbl2" cellspacing="0" cellpadding="0" style="width: 692px;">
@foreach (var list in Model.GetSaleRecords())
<tr>
<td style="font-size: large; font-style: italic; font-weight: bold" class="c1">
@list.Id
</td>
<td class="c2" ><input value="@list.bill_amt" type="text" class="data1" />
<td class="c3">@list.brand
<td class="c4">@list.product
<td class="c5"><input value="@list.price" type="text" class="data1" />
<td class="c6">@list.Qty
</tr>
</table>
Model:
public class masterList
[Required]
public virtual string _model { get; set; }
public virtual string _product { get; set; }
public virtual string _brand { get; set; }
public IList<SelectListItem> mastr_name { get; set; }
ConnectionClass con_cs = new ConnectionClass();
public SelectList getBrand()
IEnumerable<SelectListItem> BrandList = (from s in con_cs.stock_entries
select new SelectListItem()
Text = s.brand,
Value = s.brand
}).Distinct().OrderBy(x => x).ToList<SelectListItem>();
return new SelectList(BrandList, "Value", "Text", _brand);
public SelectList getProduct()
IEnumerable<SelectListItem> ProductList = new List<SelectListItem>();
if (!string.IsNullOrEmpty(_brand))
ProductList = (from s in con_cs.stock_entries
where s.brand == _brand
Text = s.product,
Value = s.product
}).Distinct().ToList<SelectListItem>();
return new SelectList(ProductList, "Value", "Text", _product);
public SelectList getModel()
IEnumerable<SelectListItem> ModelList = new List<SelectListItem>();
if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product))
ModelList = (from s in con_cs.stock_entries
orderby s.model
where s.brand == _brand && s.product== _product
Text = s.model,
Value = s.model
return new SelectList(ModelList, "Value", "Text", _model);
public List<Mydata> GetSaleRecords()
List<Mydata> query = new List<Mydata>();
if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product) && !string.IsNullOrEmpty(_model))
query = (from pd in con_cs.SaleDtls_entries
join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
where pd.brand == _brand && pd.product == _product && pd.model_no == _model
orderby od.Id
select new Mydata
Id = od.Id,
req_no = od.req_no,
product = pd.product,
brand = pd.brand,
price = pd.price,
Qty = pd.Qty,
bill_amt = od.bill_amt,
}).ToList();
else
where pd.brand == _brand && pd.product == _product
where pd.brand == _brand
return query;