How to get return value after submit?

Dondon510 221 Reputation points

How to get return value (in my case true or false) after submit?
I expect to get the return value at client side (my case return value is either true or false),
if true then it only gives me an alert('data saved') or otherwise it gives me an alert('data failed to save')

my learning01.cshtml

                           <form class="needs-validation mt-0 pt-0" novalidate asp-controller="user" asp-action="Profile">  
                                    <div asp-validation-summary="ModelOnly" class="text-danger"></div>  
                                    <input id="hHexId" type="text" hidden value="@Model.hexId" asp-for="hexId" />  
                                    <input id="hUsersPid" type="text" hidden value="@Model.usersPid" asp-for="usersPid" />  
                                    <input id="hUserEmail" type="text" hidden value="@Model.userEmail" asp-for="userEmail" />  
                                    <div class="row">  
                                        <div class="col-6 mb-1">  
                                            <label class="form-label" for="user_email">Email</label>  
                                            <span data-bs-toggle="tooltip" data-bs-placement="top" title="We will use this email address to send notifications">  
                                                <i data-feather="info"></i>  
                                            <input type="email" class="form-control" id="user_email" name="user_email" tabindex="1" value="@Model.userEmail" readonly />  
                                    <div class="row">  
                                        <div class="col-6 mb-3">  
                                            <label class="form-label" for="user_name">Username</label>  
                                            <input type="text" class="form-control" id="user_name" style="text-transform: uppercase" asp-for="userName" tabindex="2" value="@Model.userName" required />  
                                            <span asp-validation-for="userName" class="text-danger"></span>  
                                    <div class="col-12">  
                                        <button id="btnSave" type="submit" class="btn btn-page-block btn-primary mt-1 me-1">Save changes</button>  
                                        <a asp-controller="Dashboard" asp-action="Index" asp-route-id="@Model.hexId" class="btn btn-outline-secondary mt-1">Discard</a>  

my controller

public IActionResult Profile(string id, Views.User.Profile profile)  
            if (!ModelState.IsValid)  
                return View(profile);  
            bool updateProfile = Models.Users.Update_Profile(profile);  
            if (updateProfile)  
                 // how to return the true/false to client side?  
            return View("~/Views/Errs/e400.cshtml");  
A set of technologies in the .NET Framework for building web applications and XML web services.
4,249 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 58,126 Reputation points

    When the browser does a form submit, it expects the response to be a new html file. In you case a view. You return a view that display the html that represents true or false

    0 comments No comments