ASP.NET MVC学习笔记-Controller的ActionResult
2009-11-20 16:52:29 来源:WEB开发网核心提示:1. 返回ViewResult view plaincopy to clipboardPRint?public ActionResult Index() { ViewData["Message"] = "Welcome to asp.net MVC!"; return View(
1. 返回ViewResult
view plaincopy to clipboardPRint?
public ActionResult Index()
{
ViewData["Message"] = "Welcome to asp.net MVC!";
return View();
}
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
ActionResult是ViewResult基类
2.返回字符串
view plaincopy to clipboardprint?
public string GetData(string data)
{
string str = "Return String";
return str;
}
public string GetData(string data)
{
string str = "Return String";
return str;
}
3.返回ContentResult
view plaincopy to clipboardprint?
public ContentResult ContentString()
{
return Content("This is Content Result Sample");
}
public ContentResult ContentString()
{
return Content("This is Content Result Sample");
}
4.返回PartialViewResult
view plaincopy to clipboardprint?
public PartialViewResult PartiviewSample()
{
return PartialView();
}
public PartialViewResult PartiviewSample()
{
return PartialView();
}
5.返回javascript
view plaincopy to clipboardprint?
public JavascriptResult JSResult()
{
string js=@"<mce:script language='javascript'><!--
alert('This is javascript result sample);
// --></mce:script>";
return JavaScript(js);
}
public JavaScriptResult JSResult()
{
string js=@"<mce:script language='javascript'><!--
alert('This is javascript result sample);
// --></mce:script>";
return JavaScript(js);
}
6. 返回JSON字符串
view plaincopy to clipboardprint?
public JsonResult JsonString()
{
return Json(new{name="name", Sex="Sex"});
}
public JsonResult JsonString()
{
return Json(new{name="name", Sex="Sex"});
}
7.返回FileResult
view plaincopy to clipboardprint?
public FileResult FileSample()
{
return File(
"/Content/site.CSS", //文件路径
"text/css" //文件类型
);
}
view plaincopy to clipboardPRint?
public ActionResult Index()
{
ViewData["Message"] = "Welcome to asp.net MVC!";
return View();
}
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
ActionResult是ViewResult基类
2.返回字符串
view plaincopy to clipboardprint?
public string GetData(string data)
{
string str = "Return String";
return str;
}
public string GetData(string data)
{
string str = "Return String";
return str;
}
3.返回ContentResult
view plaincopy to clipboardprint?
public ContentResult ContentString()
{
return Content("This is Content Result Sample");
}
public ContentResult ContentString()
{
return Content("This is Content Result Sample");
}
4.返回PartialViewResult
view plaincopy to clipboardprint?
public PartialViewResult PartiviewSample()
{
return PartialView();
}
public PartialViewResult PartiviewSample()
{
return PartialView();
}
5.返回javascript
view plaincopy to clipboardprint?
public JavascriptResult JSResult()
{
string js=@"<mce:script language='javascript'><!--
alert('This is javascript result sample);
// --></mce:script>";
return JavaScript(js);
}
public JavaScriptResult JSResult()
{
string js=@"<mce:script language='javascript'><!--
alert('This is javascript result sample);
// --></mce:script>";
return JavaScript(js);
}
6. 返回JSON字符串
view plaincopy to clipboardprint?
public JsonResult JsonString()
{
return Json(new{name="name", Sex="Sex"});
}
public JsonResult JsonString()
{
return Json(new{name="name", Sex="Sex"});
}
7.返回FileResult
view plaincopy to clipboardprint?
public FileResult FileSample()
{
return File(
"/Content/site.CSS", //文件路径
"text/css" //文件类型
);
}
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
更多精彩
赞助商链接