none
OT: Linq query maybe someone can answer

    Question

  • MSDN Linq General is a locked forum. So, I am here asking this Linq question. 

    The Linq query is need is based on FormsCollection

    http://msdn.microsoft.com/en-us/library/system.web.mvc.formcollection(v=vs.108).aspx

    The For Each loop finds the Hidden.Control called "ActionType" and extracts the data from the control.

    How can I do this some kind of a Linq query and extract the data?

    <HttpPost>
        Function Author(id As String, vm As AuthorViewModel, formcollection As FormCollection)

            Dim dtos = New List(Of DTOAuthor)
            Dim idx As Integer
            Dim authors = Session("Authors")
            Dim action As String

           
            For Each formData As String In formcollection

                If formData.Trim.Contains("ActionType") Then
                    action = formcollection(formData)
                    Exit For
                End If

            Next

          end function

    Monday, September 23, 2013 1:33 AM

All replies

  • Hello,

    With your description, I have a try it with linq as below:

    Dim aaction = (From formData In formcollection
    
            Where formData.ToString().Contains("ActionType")
    
                     Select formcollection(formData)).ToList()
    

    My data:

    formcollection.Add("ActionType", "ActionTypeName1")
    
            formcollection.Add("ActionT1ype1", "ActionTypeName2")
    
            formcollection.Add("Action1Type1", "ActionTypeName3")
    

    And the result will return the “ActionTypeName1”.

    Hope it is that you are looking forward and be helpful to you.

    Thanks &Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 24, 2013 2:27 AM
    Moderator
  • <copied>

    Hope it is that you are looking forward and be helpful to you.

    <end>

    Thank you for the response.

    But you have not quite gotten what I need. The for each loop is working with a key/value pair I believe where it loops through until it finds "ActionType",  and then it extracts the value out of the key/value pair.

    So it should be with a Linq query that it finds "ActionType" and returns the value out of the key/value in one shot without looping.  

    Find "ActionType", extract the value "Help" and populating "action" variable.

      For Each formData As String In formcollection

                If formData.Trim.Contains("ActionType") Then
                    action = formcollection(formData)
                    Exit For
                End If

          Next

    It's being talked about in the link. Maybe Linq can't be used in this situation.

    http://forums.asp.net/t/1509054.aspx

    It's talked about here again. I just couldn't get it to work in VB, and I doubt that I could get it to work in C#. :)

    http://stackoverflow.com/questions/3831606/getting-all-selected-checkboxes-from-a-formcollection

    Thanks for any help

    Tuesday, September 24, 2013 8:00 AM