1. Query String Parameters : You can receive values from the query string in the URL.
Request URL : /Home/Index?name=John
public IActionResult Index(string name) {
}
2. Route Parameters : You can use parameters defined in the route template.
Request URL : /Home/Index/1
[Route("Home/Index/{id}")]
public IActionResult Index(int id) {
}
3. Form Data : You can receive form data from HTTP POST requests.
Request Body(form data) : name = john
[HttpPost]
public IActionResult Index([FromForm] string name)
4. Request Body : You can receive the HTTP request body. This is mainly used to receive JSON data.
Request Body(Json): {"Name":"John","Age":30}
public class User {
public string Name { get; set; }
public int Age { get; set; }
}
[HttpPost]
public IActionResult Index([FromBody] User user) {
}
5. Route Data : You can receive values from route data.
Request URL : /Home/Index/1
public IActionResult Index() {
var id = RouteData.Values["id"];
}
'asp.core > WebMvc' 카테고리의 다른 글
Convert SqlServer Tables to MVC Model using EntityFramework #2 (0) | 2019.02.12 |
---|---|
Convert SqlServer Tables to MVC Model using EntityFramework #1 (0) | 2019.02.12 |