ASPNET MVC3技术要点(14)
发布时间:2021-06-06
发布时间: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[] {
上一篇:S3C44B0 学习板使用指南
下一篇:朗文交互英语第二级A2答案