Required query string parameter in ASP.NET Core

前端 未结 5 1632
野性不改
野性不改 2020-12-18 22:11

Using ASP.NET Core 1.1 with VS2015 (sdk 1.0.0-preview2-003131), I have the following controller:

public class QueryParameters
{
    public int A { get; set;          


        
5条回答
  •  半阙折子戏
    2020-12-18 22:51

    Use model validation. You can define a ViewModel and use DataAnnotations to mark property A as [Required]. Then in your action just check if ModelState.IsValid. You can also easily do this using an action filter as shown in this article: https://msdn.microsoft.com/en-us/magazine/mt767699.aspx

提交回复
热议问题