I’m a control developer and I’m trying to design a MVC.net control. When I researched some of the MVC controls like MVC toolkit, Telerik and DevExpress etc, I’m confuse which coding style is the popular way.
For example, Telerik has its own special coding style, just like this sample:
[Code1]
Html.Telerik().Calendar()
.Name("Calendar")
.Value((DateTime)ViewData["selectedDate"])
.MinDate((DateTime)ViewData["minDate"])
.MaxDate((DateTime)ViewData["maxDate"])
It uses dot till the end. While the DevExpress allows us using lambda expression to setting so that we can write code in the View.
[Code2]
@Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvSorting";
settings.CallbackRouteValues = new { Controller = "GridView", Action = "SortingPartial" };
settings.Width = Unit.Percentage(100);
settings.Columns.Add("ContactName").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
settings.Columns.Add("CompanyName");
settings.Columns.Add("City");
settings.Columns.Add("Region");
settings.Columns.Add("Country");
}).Bind(Model).GetHtml()
Or another option is writing code in the Action and store it in the ViewData or Model, so that the [Code1] can be like:
Html.NewWay(Model).Render()
In this way, we can write all code in the action side. So maybe users are familiar with it.
I hope if you have any ideas or experience, please feel free to talk about it.
Thanks,
Howard
As you say, there are different ways to do it. It all depends on what you want to do.
The Telerik style is known as “Fluent” notation, it’s designed so that every configuration entry returns the a reference to the newly configured object, and you must guarantee you will never return null.
There is no one overriding style, people like different ways. Do whatever you think works best for you.