Results 1 to 6 of 6

Thread: [RESOLVED] MVC question

  1. #1

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    Resolved [RESOLVED] MVC question

    Hi All

    I'm working on an MVC application and I ran into a little snag.

    I've got a form with the usual textboxes and dropdowns. I decided to use jquery ajax (GET) to load the dropdowns on load (State Names & Salutations).

    No matter what I try, for example:
    Code:
     <AcceptVerbs(HttpVerbs.Get)> _
            Public Function ReturnSalutationDropdown() As ActionResult
    
                Dim dropdown As New DropDownList With {.TabIndex = 1, .DataTextField = "Value", _
                                                       .DataValueField = "Key", .ID = "ddl_coSalutation"}
                dropdown.DataTextField = "Value"
                dropdown.DataValueField = "key"
                dropdown.DataSource = AppEnumerations.BindToEnum(GetType(AppEnumerations.Salutation))
                dropdown.DataBind()
                Dim sb As New StringBuilder
                Dim tw As New IO.StringWriter(sb)
                Dim hw As New HtmlTextWriter(tw)
                dropdown.RenderControl(hw)
    
                Return Content(sb.ToString)
    
            End Function
    The ID of the dropdown ends up like: ctl00$MainContent$ddl_coSalutation

    It doesn't matter if I use a stringbuilder and a loop to create a <select> with <option>'s, the ID always ends up like above.

    Do I have to create a javascript function to create it instead?

    Thanks

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC question

    Hey,

    I haven't used an MVC application for a while, and I can't remember off hand, but is there not still the concept of a ClientID? This is what "ctl00$MainContent$ddl_coSalutation" is.

    Gary

  3. #3

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    Re: MVC question

    Hey Gep

    I thought I was finally free of ClientID.

    With MVC, I can use a MVC Master and the id's in the content areas are clean (the way they are written). Makes it super easy to use jquery or any other javascript library.

    I was really disappointed to see the mangled id in the page source when rendering a control to string. Crap.

    I read you're discussion with Motil and I guess I'll have to set the <select> in the view and simply generate the <option>s (or use another workaround)

    Cheers

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC question

    Hey,

    To be honest, this is an area that I am fuzzy on, I happened played enough with MVC 1.0, or 2.0, or that matter, or even ASP.Net 4.0, to know exactly what is going on with the ClientID. It would be interesting to hear what you find out, as I am not going to be in a position to play with this any time soon, I am stuck in SharePoint development land just now

    Gary

  5. #5

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    Re: MVC question

    Hey Gep

    Ok, it was my bad.

    I had been laying out the form before writing the ajax and I left <select id="ddl_coSalutation".... in the mark up. It was right above the target container for the returning html.

    Once I removed that from the mark up, the function worked perfectly and the id was exactly as written.

    BTW, I was a bit scared of MVC at first, but it's starting to get easy. Good luck on your sharepoint

    Cheers

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC question

    Ha ha, glad to got it sorted!

    Yeah, I think I might need it

    Gary

    P.S. Remember to mark your thread resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width