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" //文件类型
);
}