C
C#4mo ago
Massi

2 actions in one method

Hey there, I am new to C# and ASP.NET, what I am trying to accomplish now is to make account area where person updates details regarding their account. However no luck passing file and some form fields together. Any help, please? Using ASP.NET Core 8 and MVC 5. Thanks in advance.
[Authorize]
public async Task<IActionResult> Settings(IFormFile profilePhoto)
{
...
}

[HttpPost]
[Authorize]
public async Task<IActionResult> Settings(UserSettingsVM model)
{
...
}
[Authorize]
public async Task<IActionResult> Settings(IFormFile profilePhoto)
{
...
}

[HttpPost]
[Authorize]
public async Task<IActionResult> Settings(UserSettingsVM model)
{
...
}
4 Replies
Angius
Angius4mo ago
Well, you have two of the same path Either make them into one method, or make them different One being [HttpPost] and another [HttpPost("/picture")] or what have you
Massi
Massi4mo ago
Then how can I effectively merge them? because if I use both parameters ((FormFile profilePhoto and UserSettingsVM model) it won't work.
Angius
Angius4mo ago
Make the IFormFile a part of your UserSettingsVM
Massi
Massi4mo ago
Thanks a lot!