public ActionResult GetContent()

424 篇文章 1 订阅


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcAppTest1.Controllers
{
    public class TestController : Controller
    {
        public class Customer
        {
            public string CustomerName { get; set; }
            public string Address { get; set; }

            public override string ToString()
            {
                 return this.CustomerName+"|"+this.Address;
            }

        }
        //
        // GET: /Test/

        public ActionResult Index()
        {
            return View();
        }

         public string GetString()
        {
             return "Hello World is old now. It’s time for wassup bro ;)";
        }

         public Customer GetCustomer()
         {
             Customer c = new Customer();
             c.CustomerName = "Customer 1";
             c.Address = "Address1";
             return c;
         }

        [NonAction]
        public string SimpleMethod()
        {
           return "Hi, I am not action method";
        }

        public ActionResult GetView()
        {
            return View("MyView2");
        }

        public ActionResult GetView2()
        {
            return View("MyView");
        }

        static int i = 0;
        public ActionResult GetContent()
        {
            i = (++i) % 3;
            ActionResult ret = null;
            switch (i)
            {
            case 0:
                ret = View("MyContent");
             break;
            case 1:
                ret = View("MyView");
             break;
            case 2:
                ret = View("MyView2");
             break;
            }
            return ret;
           
        }

    }
}


5. ActionResult和 ViewResult的关系是什么?

ActionResult是抽象类,而ViewResult是ActionResult的多级孩子节点,多级是因为ViewResult是ViewResultBase的子类,而ViewResultBase是ActionResult的孩子节点。

6. 什么是ContentResult?

ViewResult是HTML响应而ContentResult是标准的文本响应,仅返回字符串类型。区别就在于ContentResult是ActionResult的子类。

经过了本节MVC基础知识的学习,相信大家对MVC已经有了基本的认识。大家在进行ASP.NET MVC的开发时,还可以借助一些开发工具。ComponentOne Studio ASP.NET MVC 是一款轻量级控件,与Visual Studio无缝集成,完全与MVC6和ASP.NET 5.0兼容,将大幅提高工作效率。

 

下一节,我们将讨论模型,验证,Jquery和Json。所以请持续关注吧!ComponentOne Studio!

原文链接:http://www.codeproject.com/Articles/866143/Learn-MVC-step-by-step-in-days-Day


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值