7

I am trying to add an ID HTML attribute to a form using ASP.NET MVC and VB.NET

<%Html.BeginForm("Create", "Model", "", "", New With {.id = "CreateForm"})%>

This gives me a type error, since .id is expecting an Integer, not a string. How do add an ID attribute to my form?

3
  • what language are you trying this in? VB or C#? Commented May 7, 2009 at 17:39
  • VB (see title and description) ;) Commented May 7, 2009 at 17:41
  • 1
    i would like to know the answer to this question as well Commented Feb 17, 2010 at 13:29

2 Answers 2

10

I believe you need something like this

<%  Html.BeginForm("Create", "Model", 
    FormMethod.Post, New With {.id = "CreateForm"})%>    

I think it's trying to cast one of your empty strings as the FormMethod enumeration, which won't cast correctly.

Either way check this link out, it has all the overloads for the BeginForm method.

Html.BeginForm

Sign up to request clarification or add additional context in comments.

2 Comments

you dont get intellisense whwen you type the . (dot) do you? that is, in New With {. - no intellisense right?
No because you're creating an anonymous type, so there's nothing that intellisense can provide you in that case.
2

Close:

<%Html.BeginForm("Create", "Model", "", "", new {id = "CreateForm"})%>

2 Comments

This gives me a compilation error. I'm pretty sure this will work in C#, but not VB.NET
Ahh.. Sadly, I didn't see the VB indicators. Sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.