(8) Net Core project uses Controller 3 - input parameters

1. Introduction


1. This section mainly describes several ways to receive input parameters

 

2. Unlimited mode


1. Define an id input to participate in a model input parameter.

2. Get\post view the access effect respectively.

 

api code

 1     public class OneController : Controller
 2     {
 3         public string GetString(string id, Model model)
 4         {
 5             return string.Format("getid:{0},model(id:{1},name:{2})", id, model.ID, model.Name);
 6         }
 7     }
 8     public class Model
 9     {
10         public string ID { get; set; }
11         public string Name { get; set; }
12     }
View Code

 

html code, the code of the previous article

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset="utf-8" />
 5     <title>示例代码</title>
 6     <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
 7     <script>
 8         $(function () {
 9             $.get("one/getstring", { id: "001" }, function (result) { console.log(result) });
10             $.post("one/getstring", { id: "001" }, function (result) { console.log(result) });
11         });
12     </script>
13 </head><body></body>
14 </html>
View Code

 

running result

 

 

 

 

 

 

 

 

 Three, limited mode


 1. Add FromForm restriction to model input parameters

2. View the access results of get and post respectively

 

 

 

 4. Other limited modes


1. Netcore provides 6 different limited modes, what are the specific meanings. If you have the knowledge of the http protocol, you can understand it at a glance. If you don't have it, you need to supplement the knowledge of the http protocol first .

 

 

 

 V. Conclusion


1. Under normal circumstances, the development process will not limit the parameters unless there are specific requirements. It's a lot of work that doesn't make business sense.

2. The input parameters of the api method support common types and object types, which can be flexibly selected according to business needs. Object types are exempt from the value-for-value code.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325262009&siteId=291194637