DropDownList Populated

0

Good afternoon,

I am developing a CRUD screen record in ASP.NET MVC 5, the problem is that I have fields in the form that are dropdownlist and the moment that edict has to load the options of the dropdown, however has to come select the option that the user has registered, with the option to change if the user wishes. I can send View only the option that the user has registered, but it stays static.

Controller:

 public ActionResult TicketUserEdit(int ticketId) {

        var ticketIdResult = Repository._list.FirstOrDefault(x => x.TicketId == ticketId);

        ViewBag.PriorityId   = new SelectList(ComboHelper.GetPriority(ticketIdResult.PriorityId), "PriorityId", "PriorityLevel" );
        ViewBag.ProductId    = new SelectList(ComboHelper.GetProduct(ticketIdResult.ProductId), "ProductId", "Name", Repository._product_list);
        ViewBag.SubProductId = new SelectList(ComboHelper.GetSubProduct(ticketIdResult.ProductId,ticketIdResult.SubProductId), "SubProductId", "Name", Repository._subproduct_list);
        ViewBag.TaskId       = new SelectList(ComboHelper.GetTask(ticketIdResult.ProductId, ticketIdResult.SubProductId,ticketIdResult.TaskId), "TaskId", "Name", Repository._task);
        ViewBag.VersionId    = new SelectList(ComboHelper.GetVersion(ticketIdResult.VersionId), "VersionId", "VersionName", Repository._patchlist);

        return View(ticketIdResult);
    }

    <div class="form-group">
        <div class="row">
            <div class="col-xs-3" id="div-product">
                @Html.LabelFor(m => m.ProductId , "Product")
                @Html.DropDownList("ProductId", null, htmlAttributes: new { @class = "form-control" , required = "required" })
                @Html.ValidationMessageFor(m => m.ProductId, "", new { @class = "text-danger" })
                <label id="message-product"></label>
            </div>


            <div class="col-xs-3" id="div-subproduct">
                @Html.LabelFor(m => m.SubProductId, "Sub Product")
                @Html.DropDownList("SubProductId", null, htmlAttributes: new { @class = "form-control",  required = "required" })
                @Html.ValidationMessageFor(m => m.SubProductId, "", new { @class = "text-danger" })
                <label id="message-subproduct"></label>
            </div>

            <div class="col-xs-3" id="div-task">
                @Html.LabelFor(m => m.TaskId, "Task")
                @Html.DropDownList("TaskId", null, htmlAttributes: new { @class = "form-control", required = "required" })
                @Html.ValidationMessageFor(m => m.TaskId, "", new { @class = "text-danger" })
                <label id="message-task"></label>
            </div>

        </div>
    </div>

Methods that seek

  public static IEnumerable GetProduct(int productId)
    {
        var product = Repository._product_list.Where(p => p.ProductId == productId).ToList();

        return product = product.OrderBy(p => p.Name ).ToList();
    }


    public static IEnumerable GetSubProduct(int productId,int subProductId)
    {
        var subproduct = Repository._subproduct_list.Where(p => p.SubProductId == subProductId && p.ProductId == productId).ToList();

        return subproduct = subproduct.OrderBy(p => p.Name ).ToList();
    }

    public static IEnumerable GetTask(int productId, int subProductId,int taskId)
    {
        var task = Repository._task.Where(p => p.TaskId == taskId && p.ProductId == productId && p.SubProductId ==subProductId  ).ToList();

        return task = task.OrderBy(p => p.Name).ToList();
    }
    
asked by anonymous 17.01.2018 / 18:49

0 answers