I have this RadioButton:
#Html.LabelFor(model => model.Person.Type)
#Html.Label("Type1")
#Html.RadioButtonFor(model => model.Person.Type, "F", new { disabled = "disabled" })
#Html.Label("Type2")
#Html.RadioButtonFor(model => model.Person.Type, "J", new { disabled = "disabled" })
And, I have this Display:
#Html.LabelFor(model => model.Person.Field)
#Html.DisplayFor(model => model.Person.Field)
I need a javascript function that replace this Dispay (Person.Field) if RadioButton is checked at "Type1" ("F").
How can I do this?
Related
I am not able to View the DropDown in Popup ,but i can able to view in Inline.
Here is my code
columns.ForeignKey(o => o.BreakingNewsTypeID, (System.Collections.IEnumerable)System.Web.HttpContext.Current.Application["BreakingNewsTypes"], "ID", "Description").Title("Type <!--<a href='javascript:onBreakingNewsTypes()'><span class='k-icon k-i-custom'></span></a>-->").EditorTemplateName("Alerts").HtmlAttributes(new { title = "Type" }).Width(130);
.Editable(editable => editable.Mode(GridEditMode.PopUp)
And Model for Dropdown is Alerts.cshtm
#using Kendo.Mvc.UI
#using System.Collections
#(Html.Kendo().DropDownListFor(m => m)
.BindTo((System.Collections.IEnumerable)System.Web.HttpContext.Current.Application["BreakingNewsTypes"])
//.OptionLabel("Select a value...")
.DataTextField("Description")
.DataValueField("ID")
.Events(e => e.Change("onBreakingTypeChange"))
)
I have a Kendo grid which has Excel export function. It produces a" Export to Excel" texted button and i want to change its text like "Send to Excel".
#(Html.Kendo().Grid(Model).ToList())
.Name("Grid")
.Columns(columns =>
{
//columns.Bound(p => p.BirimAd).Title("Birim").Width(500);
columns.Bound(p => p.SehirAd).Title("Şehir").HtmlAttributes(new { style = "text-align:center" }).Width(200);
columns.Bound(p => p.Value).Title("Value").HtmlAttributes(new { style = "text-align:center" }).Width(200);
//columns.Bound(p => p.Avg).Title("Avg").HtmlAttributes(new { style = "text-align:center" }).Width(200);
})
.ToolBar(tools => tools.Excel())
.Sortable()
.Excel(excel => excel
.FileName("Rapor.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export_Save", "Report"))
)
.ColumnMenu()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Excel_Export_Read", "Report"))
)
)
and excel button is producing like that:
<button class="k-button k-button-icontext k-grid-excel"><span class="k-icon k-i-excel"></span>Export to Excel</button>
I am trying this css:
<style>
.k-button k-button-icontext k-grid-excel
{
content:"Send to Excel";
}
.k-icon k-i-excel
{
content:"Send to Excel"
}
</style>
But it looks like same text. How can i change it?
Using custom command and calling export via javascript api
Razor :
.ToolBar(tools => tools.Custom("Export").Text("Send to Excel").Click("exportExcel"))
Javascript:
function exportExcel() {
var grid = $("#grid").data("kendoGrid");
grid.saveAsExcel();
});
I override the text in bound event:
#(Html.Kendo().Grid(Model)
Events(eventes => {
eventes.DataBound("bound");
})
.ToolBar(tools => tools.Excel())
.Excel(excel => excel
.FileName("Test.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("TestExcel", "Export"))
)
then in bound event:
<script>
function bound(e) {
...
$(".k-grid-excel").html('<span class="k-icon k-i-excel"></span>Exportar a Excel');
}
I think the API has changed over the years, below code works for me in 2019
.ToolBar(tb => tb.Excel().Text("Any Text") )
In my form I have:
#Html.LabelFor(m => m.Name)
#Html.ValidationMessageFor(m => m.Name)
#Html.TextBoxFor(m => m.Name, new { #class = "", placeholder = "Full Name" })
Q: How to check if field is valid and add a class to the LabelFor if it's specific field is not valid?
#Html.LabelFor(m => m.Name, if !valid: new { #class="error"} )
You're along the right lines but try this:
#Html.LabelFor(m => m.Name, new { #class= !ViewData.ModelState.IsValid ? "error" : ""} )
Using a ternary statement should work in this scenario as I use them myself on a frequent basis in normal DIV and INPUT HTML.
Edit: After chatting with Alex for a while in the StackOverflow chat system, this is the final working solution I came up with. Unfortunately, Alex is using Unobstrusive JQuery so the below code will only work if client side validation is not added.
#{
var errorCollection = new ModelErrorCollection();
if (ViewData.ModelState.Any(a => a.Value.Errors.Count > 0)) {
errorCollection = ViewData.ModelState["PropertyName"].Errors;
}
}
#Html.LabelFor(m => m.PropertyName, null, new { #class =
errorCollection.Any() ? "cssClassName" : "" })
How can I change the password box to disabled.
#Html.Editor("password")
something like
Html.TextBoxFor(model => model.User, new {disabled = "disabled"})
You're close. You have to prefix your attributes with #:
Html.TextBoxFor(model => model.User, new { #disabled = "disabled" })
You can read only text box using Html Attributes
#Html.TextBoxFor(model => model.User, new { #readonly="readonly",
style = "width:80%;" })
my code is :
#(Html.Telerik().Grid<Model>()
.Name("TestGrid")
.ClientEvents(events =>
{
events.OnDataBound("validate");
events.OnDataBinding("onDataBinding");
})
.DataBinding(db => db.Ajax()
.Select("Action1", "Controller1", new { ldata, filter }).Enabled(true)
)
.Columns(c =>
{
c.Bound(ctl => ctl.Uname)
.ClientTemplate("<input type='radio' id='rdbutton'name='IsSelected'/>")
//.ClientTemplate("<input name='<#= UserName #>' type='radio' />")
.Title("").Filterable(false).Sortable(false).Width(5);
c.Bound(itm => itm.Fname).Title("FName").Width(200).HtmlAttributes(new { #style = "vertical-align: top !important;" });
c.Bound(itm => itm.LNAme).Title("Lname").Width(200).HtmlAttributes(new { #style = "vertical-align: top !important;" });
c.Bound(itm => itm.Location).Title("Location").Width(200).HtmlAttributes(new { #style = "vertical-align: top !important;" });
})
.Selectable()
.Sortable()
.Filterable()
.Pageable(pg =>
{
pg.PageSize(3);
})
)
Columns are binded since they need to retrieve the values when search.
Yo mate,
First suggestion - use the Kendo MVC Grid - there you have an option called AutoBind which you can set to false.
If you definitely want to use the old Grid - use the OnDataBinding event and prevent it the first time.
e.g.
var isFirst = true;
function onGridDataBinding(e){
if(isFrist)
{
isFirst=false;
e.preventDefault();
}
}