这是试图代码:
@{
ViewBag.Title = "WelCome";
}<h2>WelCome</h2>
<ul>
@for (int i = 0; i < ViewBag.NumTiems; i++)
{
<li>@ViewBag.Message</li>
}
</ul>
这是控制器代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
// GET: /HelloWorld/Welome/
public ActionResult WelCome(string name, int numTimes = 1)
{
ViewBag.Message = "hello"+name;
ViewBag.NumTimes = numTimes;
return View();
}
public ActionResult Index()
{
return View();
} }
}
将控制器数据传给视图,结果是:
输入http://localhost:11997/HelloWorld/WelCome?name=jjj&numTimes=3
仅显示:
主页 关于
WelCome
但没有
hellojjj
hellojjj
hellojjj
@{
ViewBag.Title = "WelCome";
}<h2>WelCome</h2>
<ul>
@for (int i = 0; i < ViewBag.NumTiems; i++)
{
<li>@ViewBag.Message</li>
}
</ul>
这是控制器代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
// GET: /HelloWorld/Welome/
public ActionResult WelCome(string name, int numTimes = 1)
{
ViewBag.Message = "hello"+name;
ViewBag.NumTimes = numTimes;
return View();
}
public ActionResult Index()
{
return View();
} }
}
将控制器数据传给视图,结果是:
输入http://localhost:11997/HelloWorld/WelCome?name=jjj&numTimes=3
仅显示:
主页 关于
WelCome
但没有
hellojjj
hellojjj
hellojjj
解决方案 »
- 谁有办法把MSDN提供的URLRewriter里面的RewriterConfig这个节点,移到外面单独变成一个文件,而不要放在Web.Config里
- 弱弱的问:页面记录访问用户信息写入同一个文件,会不会产生冲突
- !!!求助:为什么在点击button后,刷新页面,又会执行button的事件?
- 100分 求解asp.net iis 部署问题
- 问个CheckBoxList不能布局的问题
- 在硬件区没人回答,来这里
- asp.net备份数据库,求大神支招
- asp.net与iis的权限问题
- sumanden和微软高手们,能给我treeview的具体一个实例吗?包括父,子节点的生成和SelectedIndexChange函数等等,我碰到了问题好困惑!高
- 所有的mysql工具都安装了,EF还是找不到Mysql数据源
- C#中如何实现对两个类库的互相引用?
- javascript实现验证textbox中数据是否为整数
public ActionResult WelCome(string name, int numTimes)
{
TempData["Message"] = "Hello" + name;
TempData["NumTimes"] = numTimes;
return View();
}view:
@for(int i = 0; i < int.Parse(TempData["NumTimes"].ToString()); i++)
{
<li>@TempData["Message"]</li>
}