你能解释下面的代码吗? MVC [英] Can you explain below code ? MVC

查看:52
本文介绍了你能解释下面的代码吗? MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





此代码来自互联网..

i无法理解以下代码..

i对此代码非常困惑..



任何人请帮助我理解这段代码..



 @ * @(Html.Kendo()。DropDownList()
.BindTo((IEnumerable < StackedSports.Models.SportsTeamViewModel > )ViewBag.SportsName)
.OptionLabel( - 选择体育组 - )
.DataValueField(SportsTeamGroupID)
.DataTextField(GroupName)
.Name(unvdeptspt)





问候

-AR

解决方案

通常以 @ * 开头的代码是注释,但是在编写代码时假设这是一个错误,这里是解释:

1.以 @Html开头的代码。通常是一个HTML帮助程序(标准或自定义),它呈现一个新控件甚至是局部视图到目前的页面。

2. Kendo()。DropDownList() -tll me nothing什么,如果是自定义HTML助手的一部分应该有一些参数而不是像DropDownList()这样的方法的调用;

3. BindTo 部分从获取一些数据ViewBag 命名为 SportsName ,将它们转换回类型 SportsTeamViewModel 的可枚举数据(从控制器缓存),然后将它们绑定到名为unvdeptspt的下拉列表。



但是从MVC3和MVC4我知道整个代码似乎不正确。


以上代码绑定数据来自 viewbag.sportsname  提供的第三方控件 by  telerik 用于 mvc即剑道控制,其中datavaluefield基本上包含id  datatextfield指定显示的code-keyword> text 

1 )optionlabel指定kendo下拉列表将显示的默认值。
2 )name指定您将分配给剑道下拉列表的名称 类似 正常的html控件 pre>

hi,

this code getting from internet..
i can't understand the below code..
i am very confusing about this code..

any one please help me for understand this code..

@*@(Html.Kendo().DropDownList()
                                                   .BindTo((IEnumerable<StackedSports.Models.SportsTeamViewModel>)ViewBag.SportsName)
                                   .OptionLabel("- Select Sports Group - ")
                                           .DataValueField("SportsTeamGroupID")
                                           .DataTextField("GroupName")
                                   .Name("unvdeptspt")
                                   )



Regards
-AR

解决方案

Normally the code that begin with an "@*" is a comment, but supposing that was a mistake when you write your code, here is the explanation:
1.Code that begin with @Html. normally is a HTML helper (standard or custom made) that render a new control or even partial view to the current page.
2. Kendo().DropDownList() -tell me nothing and if is a part of custom made HTML helper should have some parameters and not an invocation of a method like DropDownList();
3. BindTo part get some data from ViewBag named SportsName, convert them back to an enumerable of type SportsTeamViewModel (data that were cached from the controller), then bind them to the drop down list named "unvdeptspt".

But the entire code seems to be incorrect as I know from MVC3 and MVC4.


The above code binds data from viewbag.sportsname to the third party controls provided by telerik for mvc I.e kendo control wherein the datavaluefield basically holds the id and datatextfield specifies the text that will be displayed by the kendo dropdown.

1)optionlabel specifies the default value that the kendo dropdown will display.
2)name specifies the name that you assign to the kendo dropdownlist this is similar to what we do with normal html controls


这篇关于你能解释下面的代码吗? MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆