当前位置: 首页 > news >正文

绵阳做seo网站公司ftp上传网站后怎么弄

绵阳做seo网站公司,ftp上传网站后怎么弄,百度seo新规则,北京做网站公司哪家好在Asp.net Core之前所有的Action返回值都是ActionResult#xff0c;Json(),File()等方法返回的都是ActionResult的子类。并且Core把MVC跟WebApi合并之后Action的返回值体系也有了很大的变化。ActionResult类ActionResult类是最常用的返回值类型。基本沿用了之前Asp.net MVC的那…在Asp.net Core之前所有的Action返回值都是ActionResultJson(),File()等方法返回的都是ActionResult的子类。并且Core把MVC跟WebApi合并之后Action的返回值体系也有了很大的变化。ActionResult类ActionResult类是最常用的返回值类型。基本沿用了之前Asp.net MVC的那套东西使用它大部分情况都没问题。比如用它来返回视图返回json返回文件等等。如果是异步则使用Task。 public class TestController : Controller { public ActionResult Index() { return View(); } public ActionResult MyFile() { return File(new byte[] { }, image/jpg); } public ActionResult MyJson() { return Json(new { name json }); } public ActionResult Ok() { return Ok(); } }IActionResult接口ActionResult类实现了IActionResult接口所以能用ActionResult的地方都可以使用IActionResult来替换。同样异步的话使用Task包起来做为返回值。 public class ITestController : Controller { public IActionResult Index() { return View(); } public IActionResult MyFile() { return File(new byte[] { }, image/jpg); } public IActionResult MyJson() { return Json(new { name json }); } public IActionResult HttpOk() { return Ok(); } public async Task AsyncCall() { await Task.Delay(1000); return Content(ok); } }直接返回POCO类Asp.net Core的Controller的Action可以把POCO类型(其实不一定是POCO类可以是任意类型但是使用的时候一般都返回viwemodel等POCO类)当做返回值不一定非要是ActionResult或者IActionResult。Asp.net Core框架会帮我们自动序列化返回给前端默认使用json序列化。同样异步的话使用Task包起来做为返回值。 public class Person { public string Name { get; set; } public string Sex { get; set; } } public class ITestController : Controller { public Person GetPerson() { return new Person { Name abc, Sex f }; } public async Task GetPersons() { await Task.Delay(1000); return new List { new Person { Name abc, Sex f }, new Person { Name efg, Sex m } }; } }ActionResult T 泛型类当我们设计restful webapi系统的时候习惯使用POCO作为返回值。比如我们设计一个获取Person的api。通过 /person/001 url获取001号person。 [Route([controller])] public class PersonController : Controller { IPersonRepository _repository; PersonController(IPersonRepository repository) { _repository repository; } [HttpGet({id})] public Person Get(string id) { return _repository.Get(id); } }这个方法看起来好像没什么问题但其实有个小问题。如果repository.Get方法没有根据id查找到数据那么将会返回null。如果null做为Action的返回值最后框架会转换为204的http status code。204表示No Content 。做为restful api204的语义在这里会有问题这里比较适合的status code是404 NOT FOUND 。那么我们来改一下 [HttpGet({id})] public Person Get(string id) { var person _repository.Get(id); if (person null) { Response.StatusCode 404; } return person; }现在如果查找不到person数据则系统会返回404 Not Found 。但是这看起来显然不够优雅因为ControllerBase内置了NotFoundResult NotFound() 方法。这使用这个方法代码看起来更加清晰明了。继续改 [HttpGet({id})] public Person Get(string id) { var person _repository.Get(id); if (person null) { return NotFound(); } return person; }很不幸这段代码VS会提示错误。因为返回值类型不一致。方法签名的返回值是Person但是方法内部一会返回NotFoundResult一会返回Person。解决这个问题就该ActionResult T 出场了。我们继续改一下 [HttpGet({id})] public ActionResult Get(string id) { var person _repository.Get(id); if (person null) { return NotFound(); } return person; }现在VS已经不会报错了运行一下也可以正常工作。但仔细想想也很奇怪为什么返回值类型改成了ActionResult Person 就不报错了呢明明返回值类型跟方法签名还是不一致啊深入ActionResult T 接上面的问题让我们看一下ActionResult的内部看到这里就明白了原来ActionResult T 里面内置了2个implicit operator方法。implicit operator用于声明隐式类型转换。public static implicit operator ActionResult(ActionResult result); 表示ActionResult类型可以转换为ActionResult TValue 类型。public static implicit operator ActionResult(TValue value)表示TValue类型可以转换为ActionResult TValue 类型。因为有了这2个方法当ActionResult或者TValue类型往ActionResult T 赋值的时候会进行一次自动的类型转换。所以VS这里不会报错。总结大部分时候Action的返回值可以使用ActionResult/IActionResult设计restful api的时候可以直接使用POCO类作为返回值如果要设计既支持POCO类返回值或者ActionResult类为返回值的action可以使用ActionResult T 作为返回值ActionResult T 之所以能够支持两种类型的返回值类型是因为使用了implicit operator内置了2个隐式转换的方法
http://www.yutouwan.com/news/327167/

相关文章:

  • 工商企业查询快速seo推广排名重要吗
  • 网站编写南通建筑人才网
  • 湖州高端网站建设公司建设人力资源服务网站工作方案
  • 我的网站域名是什么上海做网站定制
  • 响应式自适应网站网站建设现状调查研究
  • 大庆市建设局网站刘东吉林省吉林市昌邑区
  • 百度广告搜索引擎公司的seo是什么意思
  • 网站建设工作计划做网站对企业的好处
  • 网站建设推广新闻手机app开发制作推荐
  • 保定网站制作系统河南省城乡和住房建设厅网站
  • 做网站个人东莞公司网站搭建多少钱
  • 永久免费的网站服务器有哪些软件国外代理ip
  • 自学网站建设作业同学录wordpress
  • 新农村建设的网站google官方版下载
  • 网站建设设计时代创信好织梦网站模板源码
  • 双公示网站专栏建设情况apicloud开发教程
  • 网站模板库官网织梦怎么做企业网站
  • 济南汽车网站设计建设网站需要体现的流程有哪些内容
  • 做外包胡it网站网站制作公透明清晰
  • 做网站用什么语音深圳网络营销十年乐云seo专家
  • 网站开发人员考核指标手机访问网站页面丢失
  • 培训加盟网站建设wordpress手机访问主题
  • 普通网站和营销型网站的区别是什么企业邮箱注册申请免费163
  • 网站开发价格预算在线oa免费crm
  • 宣传展示型网站设计免费信息发布网站有哪些
  • 站长源码论坛南宁网站建设云尚网络
  • 建设网站买了域名还要什么资料系统网站推广方案怎么做
  • 上海高端网站定设计师做私单网站
  • 让网站快速收录中国城乡住房建设厅网站首页
  • 微信 购物网站开发做网站的备案