3
I’m having a problem with my Asp.net mvc application. What’s going on is that when it comes to saving the data, my combo boxes carry data from enums. These combo boxes are from an application to a school, where the series/year, class and shift are loaded. But the problem I’m having is that, at the time I’m going to edit this data that was saved, these combo boxes return to the default value, that is, the data that is already loaded. My question is: how do I make so that when trying to change this data, they load the data that has already been saved, because all other data load normally, only the combos boxes that have this, and detail, if by chance I do not tidy the data the way it was before editing, the combo data is changed to the default values.
I’ll post their code here:
Year/Series
<div class="form-group">
@Html.LabelFor(model => model.Ano, new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select name="Ano">
@for (int i = 5; i < 10; i++)
{
<option>@i</option>
<p>º</p>
}
</select>
@Html.ValidationMessageFor(model => model.Ano)
</div>
</div>
Gang
<div class="form-group">
@Html.LabelFor(model => model.Turma, new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select name="Turma">
@foreach (var item in ViewBag.Turmas)
{
<option>@item</option>
}
</select>
@Html.ValidationMessageFor(model => model.Turma)
</div>
</div>
Shift
<div class="form-group">
@Html.LabelFor(model => model.Turno, new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select name="Turno">
@foreach (var item in ViewBag.Turno)
{
<option>@item</option>
}
</select>
@Html.ValidationMessageFor(model => model.Turno)
</div>
</div>
In the controller that was mentioned there, would it be Edit and create ? Or can you put it in the same index ? Or just Edit, where I’m having problems ?
– Érik Thiago
@Erikthiago put in the controller method that will load your view. Example: if your view is Edit put in the Edit method
– user6026
Exactly, I’m only having trouble with it. It doesn’t load the data that was registered. It always loads the default data. But if I put this method there on Dit, I’ll need to put it this way in create as well ? No right ?
– Érik Thiago
You will need to put every time you use, if in your create you have this item then you have to use it too!
– user6026
Aah, got it ! So I have to change my Edit controller and create. Just another doubt, this part here: "Dictionary<int, int> Years = new Dictionary<int, int>();", Dictionary would be my right Enum ?
– Érik Thiago
@Eric may be I don’t know how your application is because you just put your view, but the logic is this can use
– user6026
You want me to put the parts of the controller that have Edit and create it to make it easier ? If you want to put the enums that use it too ! The year is the only one I use without Enum !
– Érik Thiago
let’s go continue this discussão in chat
– user6026