Hi @Jose Daniel Navarro Brito,
a) How I show to the client via a bootstrap message box all the messages coming from the WEB API? Use
TempData
to pass messages to the view:
if (!response.IsSuccessStatusCode)
{
TempData["ErrorMessage"] = responseContent; // Store the error message
return View("/Views/Registration/Index.cshtml");
}
else
{
TempData["SuccessMessage"] = responseContent; // Store the success message
return RedirectToAction("Index", "Registration");
}
In your Razor view, add the following code to display the messages:
@if (TempData["ErrorMessage"] != null)
{
<div class="alert alert-danger">
@TempData["ErrorMessage"]
</div>
}
@if (TempData["SuccessMessage"] != null)
{
<div class="alert alert-success">
@TempData["SuccessMessage"]
</div>
}
b) Does the ModelState.Is Valid assures that all the Validations take place in the customer side hence the WEB Api doesn't have to do it?
ModelState.IsValid
checks if the model's data is valid according to the server-side validation rules. It doesn't assure that validation took place on the client-side.
c) In the event that any developer "forgets"to check the validation, is there any way that the Validation messages from the WEB API can be shown?
Not sure what do you mean the developer fogets to check, but the server side will always handle the validation.
d) Is the correct approach to set the response in a TempData and then show it in a Bootstrap message box? if so, how to do it
Using TempData
is a common approach to pass messages from the controller to the view.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena