1

I am using HTML ActionLink in MVC4. I need to remove QueryStrings using formCollection. How to Use it?

Here is my Code:

       <div class="mainNav">
            <nav>
                  <ul>
                        @for (int i = 0; i < Query.Count - 1; i++)
                        {                            
                            <li>@Html.ActionLink(Query[i].Parent_Menu,"ManageContent","Home", new { CmsFid = Query[i].CMSFunction_Id,ParentMenu=Query[i].Parent_Menu  },new { @style = "color:#FFF;text-decoration:none" })</li>

                        }
                        @for(int i=Query.Count-1;i<Query.Count;i++)
                        {
                        <li>@Html.ActionLink(Query[i].Parent_Menu,"ManageContent","Home", new { CmsFid = Query[i].CMSFunction_Id,ParentMenu=Query[i].Parent_Menu  },new {@class="last", @style = "color:#FFF;text-decoration:none" })</li>
                        }
                </ul>
            </nav>
        </div>
RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
user3350067
  • 75
  • 2
  • 10
  • 1
    Would you please consider rephrasing or expanding on your question? At the moment I'm not sure what you're doing, what you want or what you're trying to achieve. Try imagining that you're answering this question. Also read [Writing the perfect question](http://tinyurl.com/so-hints). – Rowan Freeman Mar 27 '14 at 06:03
  • please can you tell the problem you are facing – sudil ravindran pk Mar 27 '14 at 06:03
  • here I am dynamically binding menu from DataBase . when Click on menu item bind data based on ID. As of now I am using querystring Parameters to pass iD to controller. But now i want to use ormcollection to remove querystrings. – user3350067 Mar 27 '14 at 06:07
  • If you are generating dynamic menus then why do you need `Query` parameters? Check [this](http://stackoverflow.com/questions/22498255/how-to-creating-a-dynamic-sub-menus-by-sub-categories/22503615#22503615) answer if it helps. – Nilesh Mar 27 '14 at 06:16

1 Answers1

0

I dont think that you will be able to get the formCollection elements in your action (using Html.ActionLink). Also if you are able you may need to parse them or type cast them for your properties. so I recomend you to have an action method like

 public ActionResult  ManageContent(int CmsFid,string ParentMenu)
    {
    }

well you can use formCollection for form post where you may have many data

if its a form post you can use like this

 public ActionResult YourPostMethod(FormCollection formData)
{
   int CmsFid=int.Parse(formData["CmsFid"]);
}
sudil ravindran pk
  • 2,996
  • 3
  • 24
  • 29