AspNet MVC4 教学:AspNet MVC4 页面动态生成演示
HomeControllers.cs文件内容:using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcDynamicPage.Controllers { public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult DynamicOutput(string RowNum) { int iRowNum; if (int.TryParse(RowNum, out iRowNum) false) { ViewBag.Err IntTryErr; return View(Err); } if (iRowNum 0) { ViewBag.Err RowNum 0; return View(Err); } ViewBag.RowNum iRowNum; return View(); } } }Index.cshtml内容:{ ViewBag.Title Index; } html xmlnshttp://www.w3.org/1999/xhtml head meta http-equivContent-Type contenttext/html; charsetutf-8 / titleIndex/title /head body h2Index/h2 using (Html.BeginForm(DynamicOutput, Home)) { Html.TextBox(RowNum); input typesubmit value提交 / } /body /htmlDynamicOutput.cshtml内容:{ int iRowNum (int)ViewBag.RowNum; } html xmlnshttp://www.w3.org/1999/xhtml head meta http-equivContent-Type contenttext/html; charsetutf-8 / title学生花名册-共(iRowNum)个/title /head body table width400 border1 aligncenter caption 学生花名册/caption thead stylecolor:#000080;background-color:#BFBFFF tr th编 号/th th姓 名/th th年 龄/th /tr /thead tbody { for(int i0;iiRowNum;i) { tr td(i1)/td tdnbsp;/td tdnbsp; /td /tr } } /tbody /table /body /htmlErr.cshtml内容:{ ViewBag.Title Err; } html xmlnshttp://www.w3.org/1999/xhtml head meta http-equivContent-Type contenttext/html; charsetutf-8 / titleIndex/title /head body h2Err/h2 ViewBag.Err; /body /html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2504372.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!