Custom client-side checkbox column - kendo-ui

I need to implement client-side checkbox column for the grid using MVC Helper. This column must not be defined as property in Model and behave as client only. Can anyone provide an example?

You could achieve this with a template column. I am not aware of the binding, which is used in the current scenario, so I am adding examples for both (ajax and server).
E.g. Server Binding
columns.Template(#<text><input type="checkbox" name="checkbox" /></text>);
When an Ajax binding is used, you should bind the column to some property (regardless which) and specify a client template.
E.g.
columns.Bound(p => p.OrderID).ClientTemplate("<input type='checkbox' name='checkbox' />").Title("Custom title");

Related

kendo ui grid with two tables - header and data

I was trying to use the Kendo Grid UI control.
I am using the binding from Javascript with few template columns.
When the HTML is generated it gets two tables, one for header and one for body. This becomes hard for accessibility, can someone please guide me how do I set to generate only one table with header and data in it.
This issue is caused by setting grid to be scrollable. Scrollable property in Kendo UI for jQuery is true by default so you need to explicitly set it false.
If you are using Kendo UI for ASP.NET MVC then you have to remove GridBuilder's .Scrollable() method call.

'dropdownlistfor' controller not taking the selected value

I am facing an issue with dropdownlistfor controller for MVC3 razor engine, that it is not rendering with the selected value.
#Html.DropDownListFor(model => model.EmploymentStatusID, Model.EmploymentStatusList, string.Empty)
Using model am passing the data and everythng is fine till the data get to dropdownlistfor. I attached the image of cshtm page here which I got while debugging. But when rendering the selected option is not coming. What is going wrong here. Thanks in advance.
DropDownListFor does not use the Selected property of the SelectList. It uses the value of property (EmploymentStatusID in your case). In other words, it uses the value from the model, not from the SelectList.
I'm not sure why you're using a MultiSelectList anyways, a DropDownList can only have a single selected value.

Using the HTML.DropDownList helper with view model and Ajax

I'm trying to use a html.dropDownList helper with a strongly typed view model with ajax. I can't the post the code because of the nature of the project.
Here basically what I'm doing...
loading a mvc view via a strongly type view model
clicking a button which does an ajax post to a controller method
using the TryUpdateModel to parse the view model
processing the request
rendering a parital view for the ajax request
According to the article listed below, the problem is that "ASP.NET MVC assumes that if you’re rendering a View in response to an HTTP POST, and you’re using the Html Helpers, then you are most likely to be 'redisplaying a form' that has failed validation."
http://blogs.msdn.com/b/simonince/archive/2010/05/05/asp-net-mvc-s-html-helpers-render-the-wrong-value.aspx
Instead of "redisplaying the same form value", I need the html.dropDownList to be set to the same value in the view model.
Does anyone know of any custom dropDownList helpers or have any ideas of how to achieve this?
Things I've already tried/considered
per the blog, manually removing the modelstate item...didn't work - didn't pick up the value in the view model - just defaulted to the first item in dropdown list
considered just writing a regular select list...but this is sloppy and cumbersome since I'm rending multiple select lists in a loop
writing my own custom dropDownList helper...wanted to avoid reinventing the wheel
Thanks in advance
Its not fully clear to me what your problem exactly is, but I've had a similar problem. I used the Html.DropDownListFor(, SelectListItem[]) helper. At postback it sets the value to the choosen one. Your postback view doesn't require to have all the fields of the original model.
#Html.DropDownListFor(model => model.SelectedValue, MyModels.DropDownSelectables());
Here I want the selected value as the model.SelectedValue variable and within my (seperate) model I made a array of selectlistitems. The rest is automagic.
Hope it helps, D

MVC3-ValidationFailure-RetainValues

I am using MVC3 in ASP.NET. In the Post Action,
I have an View, In which it should let me edit the values. Some fields are read-only and some fields are editable. If there is a validation failure then it should retain the values and display the same View, if there are no error then it should let me to submit the form.
Control1:
Name I have to display as label as It has to be read-only
#Html.DisplayFor(Model => Model.Absentee.Name)
Control2:
I have to display this one as textbox so that it can be edited. This is a required Field.
#Html.TextBoxFor(Model => Model.AbsStart)
#Html.ValidationMessageFor(Model => Model.AbsStart) (This Makes it as a required Field)
Control 3:
This is also a textbox but not required field.
#Html.DisplayFor(Model => Model.AbsEnteredAt)
When there are no validation errors, things works great, but when there is a validation error, then I will be in the same view(Which is what I want) but the value in First control is not retained.
So Basically, when the validation failure, the value is not retained in the DisplayFor Control
What do I do to sort this?
Thank you
As 99% of my answers in the asp.net-mvc tag this one is the same: USE VIEW MODELS. Don't have your controller actions take/pass domain models to/from views. Design view models for each view. View models are classes which are specifically tailored to meet the requirements of this given view. So let's suppose that you have two different views which allow you to edit/update the same domain model. Then you will design two different view models and each view model will contain only the properties that are used by the respective view along with their specific validation requirements.
As far as the DisplatFor helper is concerned, it generates a simple label. Labels are never sent to the server when you submit a form. So you can hope to populate/validate on your controller action only the properties that are contained on the form. For properties that should not be displayed you could use either hidden fields or a single hidden field containing only some unique identifier so that you can fetch from your datastore back the original values (as the user is not supposed to modify them anyways).
As far as the mapping between the view model that you should design and the original domain model is concerned, this mapping is usually performed inside the controller and to simplify it I would recommend you to use AutoMapper.
When there is an error, what is the viewModel you are returning? DisplayFor does not get sent back to the server ... add this under the displayfor:
#Html.HiddenFor(Model => Model.Absentee.Name)

ASP.Net MVC 3: optgroup support in Html.DropDownListFor

How can i make my DropDownListFor support optgroup?
Is there anyway to do it?
Notice that this is DropDownListFor, means that it support DataAnnotation client validation
Support for optgroups was added to ASP.Net MVC at version 5.2.
The Group property on SelectListItem allows you to specify a group for each item:
New SelectList constructors also allow you to provide the name of the field that contains the group title on the supplied list of items.
The HtmlHelper DropDownList and DropDownListFor methods now generate optgroup elements based on the groups included on the list of items.
This one seems nice:
Extending the DropDownList to show the items grouped by a category, and it works for both MVC3 and MVC2.
Now Support For Optgroup In Dropdownlist .Net MVC 4
Please Check HTML5 DropDownList Optgroup Tag In MVC
#Html.DropDownGroupListFor(m => m.location_id, data, "-- Select --", new {
#data_val = "true", // for Required Validation
#data_val_required = "The Name field is required." // for Required Validation
})
Nuget Package avilable
How can i make my DropDownListFor support optgroup?
There is no built-in support in the framework for this kind of drop down lists. You will have to write your own custom helper or generate the HTML manually (I would tend towards the first option).

Resources