MVC3 使用动态生成的DropDownList,更新partial view
Demo简述:使用动态生成的DropDownlist,动态更新partial view
Control 动态生成 DropdownList 的方法
public ActionResult Index() { var products = (from product in context.GetTable<Product>() select product).ToList(); var categorys = (from category in context.GetTable<ProductCategory>() select new SelectListItem { Text = category.Title, Value = category.Id.ToString() }).ToList(); List<SelectListItem> listItem = new List<SelectListItem>(); listItem.Add(new SelectListItem { Text = "Choose an option"}); listItem.AddRange(categorys); ViewData["products"] = products; ViewData["categorys"] = listItem; return View(); } public ActionResult GetProductById(string id) { var products = from product in context.GetTable<Product>() select product; if (!string.IsNullOrEmpty(id) && id != "All") { products = products.Where(p => p.ParentId.ToString() == id); } return PartialView("ProductControl1", products.ToList()); }Index View:
<div id="loading" style="display:none;color:Red;font-weight:bolder"> Loading Data..... </div> <fieldset> <span>Choose different Product</span> <div> @using(Ajax.BeginForm ("GetProductById", new AjaxOptions { UpdateTargetId = "productList", Confirm = "Do you submit the request?", LoadingElementId = "loading", LoadingElementDuration = 2000 } ) ) { @Html.DropDownListFor(model => Model.Id,ViewData["categorys"] as List<SelectListItem>) <input type="submit" value="Submit" /> } </div> </fieldset> <div id="productList"> @{Html.RenderPartial("ProductControl1",ViewData["products"]);} </div>PartialView
@model IEnumerable<MvcApp.Product>
<table>
<tr>
<td>Title</td>
<td>Price</td>
<td>CreateTime</td>
</tr>
@foreach(var p in Model)
{
<tr>
<td>@p.Title</td>
<td>@p.Price</td>
<td>@p.CreateTime</td>
</tr>
}
</table>
- MVC3 使用动态生成的DropDownList,更新partial view
- 即使用ADO.NET,也要轻量级动态生成更新SQL
- DropDownList的动态加载,detailview使用以及FileUpload的上传
- mvc3 Razor PartialView视图中Html.DropDownList用法
- DropDownList的动态加载,detailview使用以及FileUpload的上传
- 即使用ADO.NET,也要轻量级动态生成更新SQL,比Ormlite性能更高
- 使用surfaceView结合贝塞尔曲线生成波形动态控件
- 使用Servlet动态生成图片
- [转]使用FreeMarker/Jsp(WebWork2)生成静态/动态RSS文件
- 使用CommandBuilder为DataAdaper生成的Command更新数据源时的注意事项!
- 使用Matrix生成动态列报表
- 在formview控件模板列中使用两个DropDownList控件进行联动时的操作方法
- 更新DataSet,遇到“对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成
- 数据层使用Server对象;动态生成控件多文件上传
- 使用displaytag动态生成链接
- 使用Java Servlet动态生成图片
- flash纯动态生成饼图[2007-3-14更新增加xml配置文件,可下载(转)
- 使用Java Servlet动态生成图片
- 使用Servlet动态生成图片
- Java 使用 iText动态生成PDF文档