Keeping User Experience

In order to maintain user experience, we need to store the value inside the form if the user doesn't input the correct values.

[ActionName("Add"), HttpPost]
public ActionResult AddPost(string date, string activityId, 
    string duration, string intensity, string exclude, string notes)
{
    ViewBag.Date = date;
    ViewBag.Activity = activityId;
    ViewBag.Duration = duration;
    ViewBag.Intensity = intensity;
    ViewBag.Exclude = exclude;
    ViewBag.Notes = notes;

    return View();
}

Then, we just set the form value with ViewBag. Do the following method to all tags.

<div class="form-group">
       <label for="Date" class="control-label">Date</label>
       <input type="text" id="Date" name="Date" 
              class="form-control" value="@ViewBag.Date"/>
</div>

Set the breakpoint on return value, try to build the project and press "Continue" to see the unremoved data in form.

results matching ""

    No results matching ""