I want to call an action in the controller in the view and I have to send a series of values to the controller, but the action calls the controller but sends null values. please help me
Code in view:
var _getDocumentsUrl = '@Html.Raw(@Url.Action("GetDocuments", "Document", new { Section = "0", Province = "1", County = "0", District = "0", area = "Province" }))';
Action in Controller:
public IActionResult GetDocuments(AreaVM area)
{///codes////}
Model:
public class AreaVM
{
public string? Section { get; set; }
public string? Province { get; set; }
public string? County { get; set; }
public string? District { get; set; }
}
Sending the values of section = 0, Province = 1, County = 0, and District = 0 to the controller
2
Answers
My problem was solved by changing area to model in GetDocuments action
You have to specify from what part of query your object should be constructed. Url.Action pass parameters to uri, so probably you need that ([FromUri] added):
Read this for more details:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api#using-fromuri