This is a migrated thread and some comments may be shown as answers.

Add dropdown in edit/add form.

0 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 23 Jul 2012, 08:19 PM
I'm using KendoUI along with MVC3. I want to load my dropdown in the add/update template. Right now it loads the for but as a textbox.

.cshtml
@using (Html.BeginForm("Index", "CodeManager"))
{
    <p>
        <label for="startsWith">
            <strong>Category:</strong></label>
        @Html.DropDownList("Classifications", ViewData["ClassificationItems"] as SelectList, new { style = "width:100px;" })
        <button type="submit" class="u-button">
            Search</button>
    </p>
}
@if (Model.Count() > 0)
{
        @(Html.Kendo().Grid(Model)
        .Name("CodeManager")
    .Columns(columns =>
    {
        columns.Bound(p => p.CodeID);
        columns.Bound(p => p.Title);
        columns.Bound(p => p.Status);
        columns.Command(command => { command.Edit(); }).Width(200);
    })
    .ColumnMenu()
    .ToolBar(toolBar => toolBar.Create().Text("Add New Code"))
    .Sortable()
    .Scrollable()
    .Groupable()
    .Pageable()
    .Filterable()
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
    .Resizable(resize => resize.Columns(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Events(events => events.Error("error_handler"))
        .ServerOperation(false)
        .Model(model => model.Id(p => p.Id))
         .Update(update => update.Action("Code", "CodeManager", new { classifications = @ViewBag.SelectedCatgory }))
         .Create(create => create.Action("Code", "CodeManager"))
        )
        .Editable(ed => ed.Mode(GridEditMode.PopUp))
        )
}
else
{
    @Html.Label("No records matched search criteria.");
}

Popup Editor .cshtml: Currently no dropdown..not sure how to load or display data.
@model hrmsMVC.Areas.HRMS.Models.CodeModel
<fieldset>
    <legend>Code</legend>
    @Html.HiddenFor(model => model.CodeID)
    <div class="editor-label">
        @Html.LabelFor(model => model.CodeID)
    </div>
    <div class="editor-field">
         @Html.EditorFor(model => model.CodeID)
        @Html.ValidationMessageFor(model => model.CodeID)
    </div>
     <div class="editor-label">
        @Html.LabelFor(model => model.Title)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Title)
        @Html.ValidationMessageFor(model => model.Title)
    </div>
    <div class="editor-field">
        @Html.DisplayFor(model => model.Status)
    </div>
</fieldset>

Model:
public class CodeModel
   {
 
       [Key]
       [ScaffoldColumn(false)]
       public int Id { get; set; }
 
       [DisplayName("Code ID")]
       [Required(ErrorMessage = "Code is required.")]
       [StringLength(2, ErrorMessage = "Code can be at most 2 characters")]
       public string CodeID { get; set; }
 
       [Required]
       public string Title { get; set; }
 
       [HiddenInput(DisplayValue = false)]
       public string Status { get; set; }
 
       public bool Active { get; set; }
 
       public string Category { get; set; }
 
       [ScaffoldColumn(false)]
       public int UserID { get; set; }
   }


Controller:
public ActionResult Index(string classifications = "")
        {
            ViewData["Classifications"] = new SelectList(Classifications.List, "ClassificationText", "ClassificationText", classifications);
 
            var criterion = new Criterion("Category", Operator.Equals, classifications);
 
            var codeModels = new List<CodeModel>();
            ViewBag.SelectedCatgory = classifications ?? "Type";
 
            if (Request.HttpMethod == "POST")
            {
               // var model = _codeRepository.Search(classifications).ToModel();
                var model = _codeRepository.GetList(criterion).ToModel();
                return View(model);
            }
 
            return View(codeModels);
        }

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Share this question
or