extending #Html.DropDownList mvc3 - asp.net-mvc-3

In my continuing effort to build out my form validation controls, I've gotten to the dropdownlist control and ran into a snag when I tried to customize this one.
I've tried using the TagBuilder and a simple String in extension methods to extend this control but when I try to "bind" it to a list on the back end, it's not actually binding any data to my dropdownlist. I'm sure I'm missing something (IEnumerable or the like) on my custom control but I have no idea what....any suggestions (code samples would be terrific) would be awesome.
thanks

You can go through the ASP.NET MVC source and get an idea as to how it is implemented.
Go through the License as well!!

Related

Simple yet important 4 questions about Visual Basic Studio 2012?

Guys I'm a student who knows simple stuff about Visual Basic Studio 2012 and who's working on creating an application for a course project. :)
I'm using ASP.Net Empty Website under Visual C#
If that makes sense. xD
Anyways, I have 4 important yet simple questions:
Q1: how do I apply Password Custom Vlaidation? For example 8 characters min in both the password and the password confirm text feild?
Q2: How do I apply "required" validation to a group of radio buttons, check boxes and a drop down list?
Q3: In a form, how do I get a list of radio buttons appear as options for once a customer picks a hair style category, however if she picks a make up categorty from the same drop down list, a whole different options appear? I hope it's clear lol
Q4: Is there a "range" tool in Visual Basic 2012 and how do I use it?
I appreciate every answer and so much thanks in advance. :D
For ASP.NET
Ans1:
Use RegularExpressionValidator instead of CustomValidator
Ans2:
Use RequiredFieldValidator with all the controls. And in the last use single ValidationSummary Control to display message. Here is link for you Understanding ASP.NET Validation Techniques
Ans3:
Use RadioButtonList control for options.
On SelectedIndexChange event of DropdownList control populate the RadioButtonList with relevant options.
Ans4:
Link in Ans2 will give you the RangeValidator control example.
I assume you are working in Winform.
And Since I am a C# developer I am posting my code in C#. you can use Telerik Code Converter to convert it to VB.NET
Ans1:
char[] charArray = s.ToCharArray();
int passwordCharacters = charArray.Length;
if (passwordCharacters < 8)
{
//Your code
}
Ans2:
Use ErrorProvider Control
Ans3:
There is no data bound RadioButtonList control in Winform. You will have to do it manually.
Ans4:
I don't think so there is any ASP.NET like Range Validator Control in VB.NET

Telerik problems with IntelliSense and Templates

I am working on the project where I use Telerik MVC controls in order to show some NumericTextBoxes and other controls. I have two problems that are maybe related.
1/ IntelliSense works fine in Views/Shared and in some Views. But in some it doesn´t work. The code is absolutely similar without specific blocks of code. I try to add all Telerik namespaces to Web.Config in Views folder, but it doesn´t work. Just in Views/Shared is IntelliSense working.
2/ I would like to use [SourceCodeFile] attribute in my Controller in order to using NumericTextBoxes templates. But VS says "Unknown attribute" and "Resolve" is not in context menu. I was trying to add all Telerik namespaces but it still doesn´t work.
Some suggestions?

Using a Telerik control inside a repeater

I am using the asp.net Repeater control. (My company is heavily invested in that, so I can't change it.)
I need a way to create a poup edit window, specific to the row the user clicked on in the repeater, so the user can edit the data in that record.
We have the Telerik controls to use, but I don't know which one. I saw the radwindow, but can find no examples of using it in a repeater. Frankly, Telerik documentation is confusing.
I prefer to use client-side code, ajax and web-services. I'd like to prevent post-backs.
1) Please give me a reference to a specific example of using the Telerik radwindow inside a repeater for this purpose.
OR
2) Clue me in to a better idea.
Thank you.
I don't think there are explicit examples with an asp Repeater, but I found this one with a GridView. The approach should be the same, as it is just another databound control - it shows an easy way to open a RadWindow on the client by passing some parameters (it is actually not possible to open it on the server, it is a client-side object).
Some more complex examples I found on their site here and here. They both update a grid, yet they show a nice way to use AJAX to prevent a full postback.

cshtml and ascx in one MVC3 app

Is there something wrong to use both types of views (cshtml and ascx) in single MVC3 app? We use old-school Master with server-side form. So all views are basically .aspx. But sometimes in case of partial views it is handy to use cshtml instead of ascx.
Is it ok? Or there are some troubles in future with that way?
No answers so far. Trying to answer by myself.
It's OK in general. All works fine. BUT! If you can use only one type (cshtml OR ascx), you have to use only one to make your project more unified.

mvc html.serialize to store model in view

Can anyone tell me what happened to the Html.Serialize function mentioned in the url below.
It's not recognized when I try and use it in a MVC2 web app within Visual Studio 2010.
http://weblogs.asp.net/shijuvarghese/archive/2010/03/06/persisting-model-state-in-asp-net-mvc-using-html-serialize.aspx
EDIT - I'm using visual studio 2010 which comes with mvc2 'built in' when i try and use Html.serialize on a view or partial view it's not appearing in intellisense. Am i missing a reference or something?
It hasn't gone anywhere. It is right there, wherever you are able to use the html extensions. Eg, Views, PartialViews.
For example:
<%= Html.Serialize("wizardData", Model)%>
Are you trying to use it in a controller? To use it as shown in the article you quote, you need to use it in a view.
You see, we really don't know because you haven't given us any detail to work with. Show us some code, and we will move your earth. Well, try to anyway.
I see you are new, so when asking questions, try to give as much detail as possible. You can edit your post, just mark out what you have done. The more context we get, the more we can help.
I found out why! I was having similar problems too.
You need to download ASP.NET 2 Futures and use the DLLs provided there instead of the usual Mvc DLL.
It is implemented in SerializationExtensions class.
It's in the MVCFutures assembly and not part of the out the box MVC framework. You will need to add the package via nuget or manual download and then add a using/imports statement to Microsoft.Web.Mvc before you can use it in your view.

Resources