C
C#15mo ago
massiyi

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
Angius15mo 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
massiyi
massiyiOP15mo ago
Then how can I effectively merge them? because if I use both parameters ((FormFile profilePhoto and UserSettingsVM model) it won't work.
Angius
Angius15mo ago
Make the IFormFile a part of your UserSettingsVM
massiyi
massiyiOP15mo ago
Thanks a lot!

Did you find this page helpful?