I have an Enum Class with 4 statuses which are Created, Dispatched, Delivered and Delayed in that respective order.
Currently, all 4 of these appear in the dropdown on my Edit Delivery page.
What I want is, if my status is Created then I should ONLY be able to change it to Dispatched, if my status is Dispatched I should ONLY be able to change it to Delivered or Delayed, and if my status is Delayed I should ONLY be able to change it to Dispatched or Delivered.
This should all happen on my Edit Delivery page. You'll also notice that I don't want Created in either of the lists above as I only require it in Create Delivery.
So, essentially I want to achieve is when my delivery status is set to Created, I should only see Dispatched in my Enum Dropdown when I wish to Edit that Delivery. Similarly for Dispatched, if my status is set to dispatched then I only want to see Delivered or Delayed. Same for Delayed, I only want to see Dispatched and Delivered.
I'm fairly new to MVC and if anyone can suggest a solution for this, I'll greatly appreciate it!
Please let me know if any additional code is required and I will add it to the question.
Enum Class:
public enum Status
{
Created, Dispatched, Delivered, Delayed
}
Delivery View Model:
public class DeliveryVM
{
public int? ID { get; set; }
public Status Status { get; set; }
}
Delivery Edit View:
<div class="form-group">
@Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(model => model.Status, htmlAttributes: new { @class = "form-control", @id="dropdown" })
@Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
</div>
</div>