手机版

ASPNET MVC3技术要点(14)

时间:2025-07-07   来源:未知    
字号:

ASPNET MVC3技术要点

if (prod != null) {

repository.DeleteProduct(prod);

TempData["message"] = string.Format("{0} was deleted", ); }

return RedirectToAction("Index"); }

3.2.3.3 重定向到一个路由系统的URL public RedirectToRouteResult Redirect() { return RedirectToRoute(new {

controller = "Example", action = "Index", ID = "MyID" }); }

3.2.4 输出Text数据

3.2.4.1 输出纯文字数据

public ContentResult Index() {

string message = "This is plain text";

return Content(message, "text/plain", Encoding.Default); }

3.2.4.2 输出XML数据

public ContentResult XMLData() {

StoryLink[] stories = {

new StoryLink("First example story" ,"This is the first example story","/Story/1"),

new StoryLink("Second example story" ,"This is the second example story","/Story/2"),

new StoryLink("Third example story" ,"This is the third example story","/Story/3")

};

XElement data = new XElement("StoryList", stories.Select(e => {

return new XElement("Story", new XAttribute("title", e.Title),

new XAttribute("description", e.Description), new XAttribute("link", e.Url)); }));

return Content(data.ToString(), "text/xml"); }

3.2.4.3 输出JSON数据

public JsonResult JsonData(string id) {

IEnumerable<Appointment> data = new[] {

ASPNET MVC3技术要点(14).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)