In mvc project,I have some optional values so need to correspondent control must not be mandatory.

Property is

[Display(Name = "Transaction type")]
public int TransactionTypeID { get; set; }

Razor syntax for control is

<div class="form-group">
@Html.LabelFor(m => m.TransactionType, new { @class = "col-md-3 control-label" })
    <div class="col-md-3">
     @Html.DropDownList("TransactionTypeID", null, "Select tran", new { @placeholder = "Select tran type", @class = "form-control" })

Controller syntax to fill the control

private void LoadTransactionTypesInViewData(object selectedValue = null)
    var datas = transactionTypeRepository.GetAll().OrderBy(p => p.Name);
    ViewBag.TransactionTypeID = new SelectList(datas, "TransactionTypeID", "Name", selectedValue);

Why my drop down list mandatory, why not it optional.How to make it optional.

Related posts

Recent Viewed