How do i data-bind the MVVM value to my dropdownlist? The input element below works well
<input class="k-textbox" placeholder="hotel business registration" required data-bind="value: dataItem.HotelStatusId"/>
I doesn't when i try to use KendoUI dropdownlist instead
#Html.Kendo().DropDownList().BindTo(new SelectList(ViewBag.HotelStatuses, "Id", "Name")).Value("#=dataItem.HotelStatusId#").Name("ddl-hotel-status");
this does not work either
#Html.Kendo().DropDownList().BindTo(new SelectList(ViewBag.HotelStatuses, "Id", "Name")).Value("dataItem.HotelStatusId").Name("ddl-hotel-status");
Found the solution, here's the working code.
#Html.Kendo().DropDownList().BindTo(new SelectList(ViewBag.HotelStatuses, "Id", "Name")).Name("ddl-hotel-status").HtmlAttributes(new Dictionary<string, object>{{"data-bind", "value: dataItem.HotelStatusId"}})
Related
Can anyone help me with kendo ui masked textbox.
How can I give a multi line option to a kendo ui masked textbox.
How about this using a text area ?
<textarea data-role="maskedtextbox"
data-mask="(999) 000-0000-00000-aaa (234580)"
rows="4"
data-bind="visible: isVisible,
enabled: isEnabled,
value: phoneNumber,
events: { change: onChange }"
style="width: 200px"></textarea>
Please take a look at this kendo dojo
The existing solution for dropdownlist:
<input id="countryid" name="countryid"
data-role="dropdownlist"
data-text-field="text"
data-value-field="value"
data-bind="value: countryid"
data-source="CountryidNameList"
data-auto-bind="true"
data-bound="updateModel"
data-value-primitive="true"/>
function updateModel(e) {
var widget = e.sender;
setTimeout(function() {
widget.trigger("change");
});
};
when we migrate to new version of Kendo UI 2015 (commercial version), the above solution does not work any more:
for form, the dropdownlist does not set the first value of the dropdownlist any more;
for kendo-grid (change the input, but still use the updateModel function), in edit mode: the dropdownlist is showing a loading icon (there is no error and the value is loaded in the dropdownlist while click)
anyone can help?
Well you can modify your kendo element a bit as:
<input id="countryid"
name="countryid"
data-text-field="text"
data-value-field="value"
data-option-label="Select Country..."
data-bind="source: CountryidNameList,value:countryid" data-role="dropdownlist"
></input>
and do the source binding from javascript. Have done a JSBin for your issue here. Hope you find it useful!
im using dropdownlists in my kendogrid popup forms. im using them in template like
<label for="primaryClient" style="text-align:left">Primary Account*</label>
<div class="k-edit-field"><input name="primaryClient" data-bind="value:primaryClient" data-value-field="value" data-text-field="text" data-source="dsDocClientGroup" data-role="dropdownlist" required validationMessage="Required" /></div>
However when i check whats actually being posted. its posting an array:
primaryClient['label'],
primaryClient['value']
any ideas while this would be happening
Please suggest me regarding one issue. I am using MVC3 Razor webgrid I need 2 input submit/button [Edit/Delete] in each row. Should be button not link. Code is something like this.
#grid.GetHtml(columns:
grid.Columns(
grid.Column("ID", "id"),
grid.Column("Value", "Value"),
grid.Column(format: #<input type="button" value="Edit"/>),
grid.Column(format: #<input type="button" value="Delete"/>))
)
I have to do on server no javascript function.
Thanks a lot
You can use ACTION LINK here,
#grid.GetHtml(columns:
grid.Columns(
grid.Column("ID", "id"),
grid.Column("Value", "Value"),
grid.Column(format: #Html.ActionLink("Edit", "EditAction", new { id = item.id}),
grid.Column(format: #Html.ActionLink("Delete", "DeleteAction", new { id = item.id})
)
you can then define a nice css for it to make it look like a button,
refer
http://www.dofactory.com/topic/1015/html-actionlink-and-class-attribute.aspx
After trying options I accomplish this using a hidden field. On click button populate hidden field with javascript and submit form using javascript.
grid.Column(format: #<form method="get"action="/Controller/Action/#item.id">
<input id="Submit" type="submit" value="Edit" />
</form>)
autocomplete text box for getting city autocomplete textbox.
My code look like this,
<input id="location" type="text" name="q"
data-autocomplete="#Url.Action("locationSearch", "Home",
new { text = "location" })"/>
Now i want to convert this to razor syntex. I tried this but not working.
#Html.TextBoxFor(model => model.Location,
new { data-autocomplete = Url.Action("locationSearch", "Home")})
How can i solve this??
data-autocomplete is an HTML attribute. First of all you can't use dashes when specifying attributes in MVC, therefore you need to replace your data-autocomplete with data_autocomplete. MVC is "smart enough" and final result will read data-autocomplete.
To add an HTML attribute to your text input you need to use the following HTML helper:
#Html.TextBoxFor(model => model.Location, new { data_autocomplete = Url.Action("locationSearch", "Home") })
Please work on your acceptance rate.
u can just use this
in your view
<select id="location" name="location"></select>
<input type="submit" value="Send">
that is actually dropdownlist, not textbox, they edit the layout via css
You should use undescore symbol in HtmlAttributes argument:
#Html.TextBoxFor(model => model.Location, new { data_autocomplete = Url.Action("locationSearch", "Home")})