ASPNET MVC3技术要点(14)

发布时间:2021-06-06

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文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219