AspNet MVC4 教学:AspNet MVC4 页面动态生成演示

张开发
2026/4/10 23:33:42 15 分钟阅读

分享文章

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

更多文章