Benefit Set: </label><br />
<%: Html.DropDownListFor(model => model.bvODSMapping.Benefit_Set, Model.BenefitSet,new {id="BSet", style = "width:230px;" })%>
When I am using model=>model.bvODSMapping.Benefit_Set.Trim()
I am getting Value Can not be null.
can anybody help me out how to trim the string?
Thanks
I guess it would be the best to trim the values before passing the model to your view.
Nevertheless, this might help:
#Html.DropDownListFor(
model =>
model.bvODSMapping.Benefit_Set,
Model.BenefitSet.Select(
item =>
new SelectListItem
{
Selected = item.Selected,
Text = item.Text.Trim(),
Value = item.Value
}),
new { id = "BSet", style = "width:230px;" })
Related
Say if I have this textbox
#Html.TextBoxFor(x => x.Name, new {id = "add-name", data_parsley_maxlength = "1" })
How do I write my LabelFor so that it references "add-name"?
Or do I have to use #Html.Label?
I have the following DropDownListFor that displays a list of states for the user to choose from. How can I default the dropdown to be empty. It currently defaults to the first state in alphabetical order ("Alaska")
#Html.DropDownListFor(m => m.User.StateID,
new SelectList(Model.User.States.Where(filter => filter.Active && (filter.CountryID == 1))
.Select(item => new
{
ID = item.StateProvinceID,
Description = item.Name
}),
"ID",
"Description",
Model.User.StateID),
new { #data_bind = "value: user.StateID, enable:!isSiteUser()", tabindex = "10" })
I figured out that one of the posted questions did have the correct answer for my problem. I was just trying to do use it incorrectly. I was adding "string.Empty" to the wrong location. This is the solution.
#Html.DropDownListFor(m => m.User.StateID,
new SelectList(Model.User.States.Where(filter => filter.Active && (filter.CountryID == 1))
.Select(item => new
{
ID = item.StateProvinceID,
Description = item.Name
}),
"ID",
"Description",
Model.User.StateID),
string.Empty,
new { #data_bind = "value: user.StateID, enable:!isSiteUser()", tabindex = "10" })
#Html.DropDownListFor(m => m.Baled, new SelectList(new [] {"Select Type","Option1", "Option2", "Option3"}))
I want to add a css class in the dropdown list.
I have tried this
#Html.DropDownListFor(m => m.Baled, new SelectList(new [] {"Select Type","Option1", "Option2", "Option3"}, new {#class="myclass"}))
But it doesn't work
If anyone can suggest me any other better way to display dropdown list will be ok too.
You have close the bracket at wrong place. you have defined attribute in second paramter of selectlist. actually it should be close first and define in the last parameter of Html.DropDownListFor
#Html.DropDownListFor(m => m.Baled, new SelectList(new[] { "Select Type", "Option1", "Option2", "Option3" }), new { #class = "myclass" })
I have a EditorTemplate in a PartialPageView for a DateTime which has three DropDownLists for the day, month, and year. When I try to update the values the postback Date is always 01/01/0001. Any ideas?
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%= Html.DropDownListFor(x => x.Value.Day, Enumerable.Range(1, 31).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString(), Selected = i == Model.Value.Day ? true: false})) %>
<%= Html.DropDownListFor(x => x.Value.Month, Enumerable.Range(1, 12).Select(i => new SelectListItem { Value = i.ToString(), Text = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i), Selected = i == Model.Value.Month ? true : false }))%>
<%= Html.DropDownListFor(x => x.Value.Year, Enumerable.Range(1900, 110).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString(), Selected = i == Model.Value.Year ? true : false }))%>
To handle this case you might need to write a custom model binder.
I could create a grid with telerik mvc
<% Html.Telerik().Grid(Model)
.Name("ProductGrid")
.Columns(columns => {
columns.Bound(h => h.ProductName).Width("34%");
columns.Bound(h => h.Description).Width("60%");
columns.Bound(h => h.ProductID).Format(Html.ImageLink("Edit", "Products", new { Id = "{0}" }, "/Content/images/icon_edit.gif", "", new { Id = "edit{0}" }, null).ToString()).Encoded(false).Title("").Sortable(false).Width("3%");
columns.Bound(h => h.ProductID).Format(Html.ImageLink("Delete", "Products", new { Id = "{0}" }, "/Content/images/icon_delete.gif", "", new { onclick = string.Format("return confirm('Are you sure to delete this add on?');") },null).ToString()).Encoded(false).Title("").Sortable(false).Width("3%");
})
.EnableCustomBinding(true)
.DataBinding(databinding => databinding.Ajax().Select("_Index", "ProductGrid"))
.Pageable(settings => settings.Total((int)ViewData["TotalPages"])
.PageSize(10))
.Sortable()
.Render(); %>
but I need to add a serial number column in telerik grid.How can i do this?
I think the best way is to use template column like this.
<%
var sn = 0;
Html.Telerik().Grid(Model).Name("Grid").HtmlAttributes(new { style = "width:auto" })
.EnableCustomBinding(true)
.Columns(columns =>
{
columns.Template(c=> {%> <%: ++sn %> <% }).Title("S/N");
columns.Bound(c => c.CustomerNumber);
columns.Bound(c => c.Narration);
})
.Render(); %>
This way you don't have to be adding serial number property to your view models.
Hope this help?
I think the best way to do this is to add a SerialNumber column to your Product class which is your model and than just add another bound column to the grid like this:
columns.Bound(h => h.SerialNumber)
If you pass a List of Products you can populate the SerialNumber column like this:
List<Product> products = GetList(); // Your method to get data here
int counter = 1;
products.ForEach(x => x.SerialNumber = counter++);
If you want to support consistent numbers with paging you have to calculate yourself the initial value of the counter valuable. For this purpose you must have the current page and page size.
In MVC Web Grid
use this calculation
grid.Column(header: "#",
format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex),