惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 王伟晔

docker 主从mysql配置 利用asp.net Core开发webapi对接云之家智能审批数据互联控件 Windows 2012安装odoo12 Windows有点腻了?不如试试Ubuntu. 处理范例代码Webapi中的Mongodb的Bson中ObjectId反序列化异常 用app.net Core搞掂多国语言网站 重建程序员能力(2)-如何使asp.net mvc应用增加js和其他功能 重建程序员能力(1) asp.net mvc 5发布部署遇到403.14 我需要在Web上完成一个图片上传的功能(+2) 我需要在Web上完成一个图片上传的功能后续(+1) 我需要在Web上完成一个图片上传的功能 android-studio-bundle-141.1980579-windows download Site Razor提高WebPage代码的易读性 C# Hello World - 王伟晔 用params关键字增强代码的可读性 陌生的yield关键字 发现Visual Studio隐含的大礼包--漂亮的Visual Studio图像库 职业程序员必须要有的工作态度(之一)
重建程序员能力(3)-asp.net MVC框架增加Controller
王伟晔 · 2017-02-26 · via 博客园 - 王伟晔

    MVC在微软中提供的框架目前只是发现是asp.net用。另 8年前,我做了个MVC的Windows APP框架如果有兴趣我日后会介绍给大家,欢迎大家关注。MVC的概念网站上有很多,大家去查阅一定能看到,这里不重复讲述了。这里只是介绍怎么加。

1. 找到asp.net项目,然后好到Controller文件夹,右键展开菜单 [添加] 展开下一层菜单,然后选择[控制器]。

06

2.在对话框中有3个选项,这次为表述方便先用空的MVC5控制器

image

3.填写一下控制器的名称按添加即可。

需要注意的是Controller是必要的结尾。这个是MVC框架用于路由的。

image

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

namespace WebMVCApp.Controllers
{
    public class ReqOrderController : Controller
    {
        // GET: ReqOrder
        public ActionResult Index()
        {
            return View();
        }
    }
}

新建出来的cs文件类似这样。

3. 写个简单的例子,在Controller的代码提中增加一个Welcome方法

          // GET: ReqOrder
        public string Welcome()
        {
            return "This is app for request Order submit."; 
        }

这段代码是一旦调用这个控制器的Welcome就返回一串字符。类似HelloWorld的Output了。

4.可以按F5测试一下了。image

跟写的不一样吧,对的,当前页面是默认的页面,还没有到刚才写的Controller处理的位置。

5.测试Controller

在服务入口中添加控制器和需要测试的方法。

显示的页面就是刚才的想过了

image

与其他网页处理的不一样,这里返回的真的只是字符串,而不是html页面,不信可以使用右键菜单查看一下代码看看。

image

Winking smile

总结

1.Controller新建的时候必须已“Controller”结尾,需要注意大小写规范哦。

2.调用Controller的时候,是页面访问的地址,中有服务器根地址,加Controller的名称不包含Controller部分,然后加方法名。

#补充:

  • 我看过微信的Api资料,在微信公众号配置的时候,需要验证服务器端的地址是否配置正确,微信会按配置的地址调用网页,然后要求服务器能回复