how find kendo treeview id or name on checkbox checked changed - asp.net-mvc

how find kendo tree view name or id on checkbox checked changed.
#(Html.Kendo().TreeView().Name("treeName")
.Checkboxes(c => c.Name("checkBoxes").CheckChildren(true))
.AutoScroll(true)
.Events(e => e.Check("onCheck"))
)
javascript code:
function onCheck(e) {
//how find tree name or id here??
}

First you must set you tree name if it is as you wrote "treeName" than it will look like this.
function onCheck(e) {
$("#treeName").getKendoTreeView().dataItem(e.node).id
}
Or you can search by UID
var treeviewName = $("#treeName").data("kendoTreeView");
var getitemByUid = treeviewName.dataSource.get();
treeview.findByUid(getitemByUid.uid);
var selectitemByUid = treeview.findByUid(getitemByUid.uid);
treeview.select(selectitemByUid);

Related

Access value enumeration field fom content part in Editor Method Orchard

I want to access the selectedvalue (enumeration field) in content part when click submit save button in widget administrator. How I can do that in Editor Method?
If you know the name of the ContentPart that has that field, you can do it like this:
(dynamic)contentItem.ContentPartName.FieldName.SelectedValue
But if you don't know the name of the ContentPart, you can first use this to get all the fields of the content item at runtime:
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;
// get all the fields from the contentItem without knowing part name
var callSite = CallSite<Func<CallSite, object, object>>
.Create(Binder.GetMember(0, contentItem.ContentType,
((dynamic)contentItem).GetType(), new[] { CSharpArgumentInfo.Create(0, null) }));
var contentItemFields = ((callSite.Target(callSite, ((dynamic)contentItem))).Fields) as List<ContentField>;
Having the list of fields, you now can search for the EnumerationField that you want, and get the selected value:
var yourField = (contentItemFields.FirstOrDefault(f => f.name == "YourField")) as EnumerationField;
var selectedValue = yourField.SelectedValue;

Using Dropdownlist selected value in IF statement MVC

I am new to MVC. I am trying for Cascading Dropdownlist in ASP.NET MVC 4. My problem is I want to access the selected countryid in #foreach loop
#Html.DropDownList("ddlCountry", new SelectList(#Model.Countries, "CountryId", "CountryName"))
$("#ddlCountry").change(function () {
#foreach (var item in #Model.States.Select(x=>x.countryId = ?))
{
}
});
How can I substitute countryId with the question mark above, so that I can filter the states
Thanks in Advance
Thanks
SRRIN
you can get the value in jquery by this
$("#ddlCountry option:selected").text();
As #Stephen said you cannot get the value of selected option using razor. Because the razor code is executed before page load.
A work around would be
$("#ddlCountry").change(function () {
var selectedVal= $("#ddlCountry option:selected").text();
var list = #Model.States.Tojson();
});
then use inArray for doing further operations
Thanks to all.
As Stephen and Nikitesh stated, javascript variable are not accessible inside razor scripts. So I succeeded with following approach.
var selectedCountryId = $("#ddlCountry").val();
var states = #Html.Raw(Json.Encode(Model.States));
for (var i = 0; i < states .length; i++) {
if (states [i].countryid == selectedCountryId ) {
... populate states here
}
}
Thanks
SRRIN
you can use dropdown selected value and pass in your query as:
#Html.DropDownList("ddlCountry", new SelectList(#Model.Countries,"CountryId", "CountryName"))
$("#ddlCountry").change(function () {
var countryId=parseInt($(this).val());
#foreach (var item in #Model.States.Select(x=>x.countryId = countryId))
{
}
});

extract value from XML file and navigate it to its corresponding URL using MVC (i dunno how to navigate it to its particular URL.)

I have an XML file with several environment names and corresponding URL to the environment name.
Requirement is:
1. display the environment names in a dropdownlist
2. select any environment name in dropdownlist.
3. Click Navigate link below dropdown button.
4. The page should be navigated to particular URL, which the environment name belongs to.
EX: (from XML File)
I want to fetch "name" & "LMHost" .
I completed upto creating dropdownlist. Binding environment name inside dropdownlist. But i dunno how to navigate it to particular URL.
My Controller Code
var xDoc = XDocument.Load(fileName);
IEnumerable<XElement> envGroups = from xmlDoc in xDoc.Descendants().Elements("environment")
select xmlDoc;
model.EnvironmentName = from envName in envGroups.Attributes("name")
select new SelectListItem
{
Text = envName.Value,
Value = envName.Value.ToString(),
Selected = (envName.Equals(envName))
};
return View(model);
View Code
<%=Html.DropDownList("EnvironmentName", new SelectList (Model.EnvironmentName, "Value" , "Text")) %>
Model Code
public IEnumerable _environmentName;
[DisplayName("EnvironmentName")]
public IEnumerable<SelectListItem> EnvironmentName
{
get
{
if (_environmentName == null)
_environmentName = new List<SelectListItem>();
return _environmentName;
}
set { _environmentName = value; }
}
Kindly help me. I find difficult to navigate the environment names to its particular URL
As mentioned above, window.location will work
Include jquery on your page, and add a button or anchor to your page with the onclick action:
window.location=$('#EnvironmentName').val();
You can prefix/suffix the location to create the correct path e.g.:
window.location='http://yoursitepath/' + $('#EnvironmentName').val() + '.html';

Change the Telerik DateTimePicker element ID, but keep the name

I have a ASP.NET MVC page with multiple forms on it, where each form edits a different instance of the same class. Each form also includes a Telerik DateTimePicker control. What I want is to have the element IDs change, but not the element name. So I have something like this:
string idString = string.Format("MyObject{0}", Model.ID)
#Html.Telerik().DatePickerFor(m => m.SomeDate).HtmlAttributes(new { id = idString + "-SomeDate" })
Now this works mostly fine, except that at the bottom of the page, the auto-generated Javascript that Telerik puts in looks like:
jQuery('#SomeDate').tDateTimePicker({
format:'M/d/yyyy h:mm tt',
minValue:new Date(1899,11,31,0,0,0,0),
maxValue:new Date(2100,0,1,0,0,0,0),
startTimeValue:new Date(2013,3,22,0,0,0,0),
endTimeValue:new Date(2013,3,22,0,0,0,0),
interval:30,
selectedValue:new Date(2013,3,22,11,9,1,180)
});
Note that my idString value didn't get put in. I can try:
#Html.Telerik().DatePickerFor(m => m.SomeDate).Name(idString + "SomeDate")
And this makes the auto-generated Javascript correct (jQuery('#MyObject123-SomeDate')) but now the element name is wrong, so TryUpdateModel fails.
How can I get this to work? Thanks.
EDIT: I hacked this using the following Javascript, but this is a kludgy way to fix this.
$(function () {
window.setTimeout(function () {
for (var i = 0; i < document.getElementsByTagName("input").length; i++) {
var obj = document.getElementsByTagName("input")[i];
if (obj.id.indexOf("SomeDate") == -1)
continue;
obj.name = "SomeDate";
}
}, 150)
});
The solution was to use the Telerik object's .InputHtmlAttributes method.
#Html.Telerik().DatePickerFor(m => m.SomeDate).InputHtmlAttributes(new { id = idString + "-SomeDate" })

Telerik MVC Chart ClientEvents.OnDataBinding

I want to show a poll result for a specific poll question.
When question list clicked i want to bind my chart with a query according to selected questionId.
So my plan was;
1. get questionId from selected question row. it's ok.
defining ClientEvents.OndataBinding event on my chart. So i would be able to
pass questionId with;
function onChartDataBinding(e) {
e.data = $.extend(e.data, { questionId: questionId });
}
using $('#ChartPollResults').data('tChart').rebind(); on question list grid row selected event.
This scenario works when i have second grid binding according to first grids selected row.
But it seems there is no ClientEvents.OnDataBinding event on chart control.
And "rebind()" method isn't supported on Chart control.
The chart conrol i use is below.
#(Html.Telerik().Chart<QuestionResult>()
.Theme("WebBlue")
.Name("ChartPollResults")
.Title("Poll Question Choice Number vs. Choice Count")
.Legend(legend => legend.Position(ChartLegendPosition.Bottom))
.Series(series =>
{
series.Bar("ChoseCount").Name("Choice Count").Gap(5);
})
.CategoryAxis(axis => axis.Categories(o => o.ChoiceNumber))
.DataBinding(dataBinding => dataBinding.Ajax().Select("_PollResultChartBinding", "Poll", new { questionId = 0 }))
.HtmlAttributes(new { style = "width: %100px; height: 270px" })
)
My Controller binding method;
public ActionResult _PollResultChartBinding(int questionId = 0)
{
//questionId = 3;
if (!ModelState.IsValid || questionId == 0)
return Json(new List<QuestionResult>());
PollQuestionDefinition pollQuestion = service.Get(questionId);
List<PollAnswer> pollAnswers = service.GetPollAnswersByQuestion(questionId);
PollQuestionResultUI result = new PollQuestionResultUI(pollQuestion, pollAnswers);
return Json(result.Results);
}
When i comment out //questionId = 3; line i can see the results for the question wiht Id= 3 in chart with no problem.
But i can't pass questionId to chart.
Thanks in advance.
This is my Opinion for your source code should be like this:
//controller binding method
public ActionResult _PollResultChartBinding(string questionId)
{
//questionId = 3;
int _questionId = String.IsNullOrEmpty(questionId) ? 0 : Convert.ToInt32(questionId);
if (_questionId == 0)
return Json(new List<QuestionResult>());
PollQuestionDefinition pollQuestion = service.Get(_questionId);
List<PollAnswer> pollAnswers = service.GetPollAnswersByQuestion(_questionId );
PollQuestionResultUI result = new PollQuestionResultUI(pollQuestion, pollAnswers);
return Json(result.Results);
}
**in your view, there is no problem with the code**.
but, for rebind that chart, this is the code :
example : (running from developer console for IE or firebug for firefox browser)
var chartPollResult = $('#ChartPollResults').data('tChart');
chartPollResult.rebind({ questionId: "0"});
but if you want make it into function, code should be like this:
function rebindChartPollResult(e, param) {
e.data('tChart').rebind({ questionId: param});
}
calling method :
rebindChartPollResult($('#ChartPollResults'), "0");
reference for telerik chart ajax binding (not included how to rebind chart) :
http://demos.telerik.com/aspnet-mvc/chart/ajaxbinding
First of all, one thing I immediately noticed is that you set questionId equal to 0 in your ActionResult parameters. I actually just modified a Chart I had up and running to pass in
new { questionID = 0}
as an additional parameter to my Ajax select statement and it passed in fine.
As for passing the parameter you could consider using a POST to the server on Grid selection and pass the parameter that way. I know it might not be ideal here, but you could theoretically either populate the Chart in that post, or just set a ViewData entry to contain the particular questionID that you are looking for.
I also noticed that you submitted this to the Telerik forums and from the response there it would seem that the above approach might actually work pretty well, or you could use the approach mentioned there (partial view with ajax calls).

Resources