connectseekers.com

Friday, 19 June 2015

MVC Pass Multiple Parameters in QueryString or URL in Asp.Net MVC

6/19/2015 - By Pranav Singh 1

This article will show you how you can  MVC Pass Multiple Parameters in QueryString or URL in Asp.Net MVC using c#. In this you will learn to pass and access multiple QueryString value in URL in asp.net mvc using c#.

Some of my previous articles are as follows: jQuery Articles, Partial view in Asp.Net MVC, jQuery Ajax Search and Display In MVC WebGrid in Asp.Net MVC Using C#.Net, Search and Display Data In MVC WebGrid in Asp.Net MVC Using C#.Net, Hyperlink Adding In MVC WebGrid in Asp.Net MVC Using C#.Net.

So for this article first will create a new asp.net mvc application and add a controller file and in this we will add two action method. One for providing link and in which we will pass the value and other for accessing the request querystring value.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult IndexOutput()
        {
            string FirstName = Request.QueryString["FirstName"].ToString();
            string LastName = Request.QueryString["LastName"].ToString();
            string Marks = Request.QueryString["Marks"].ToString();

            ViewData["FirstName"] = FirstName;
            ViewData["LastName"] = LastName;
            ViewData["Marks"] = Marks;

            return View();
        }
    }
}

In above code I have passed the request QueryString by storing into ViewData to display in view. Now we will create the view and add the below code.

@{
    ViewBag.Title = "MVC Pass Multiple Parameters in QueryString or URL in Asp.Net MVC";
}

@using (Html.BeginForm("Index", "Home"))
{  
    <a href="Home/IndexOutput/?FirstName=John&LastName=Mathu&Marks=80%"><b>Click to Redirect</b></a>
}

Second one.

@{
    ViewBag.Title = "IndexOutput";
}
<h4>
    MVC Pass Multiple Parameters in <br />QueryString or URL in Asp.Net MVC</h4>

    <div>
        First Name :@ViewData["FirstName"]<br />
        Last Name :@ViewData["LastName"]<br />
        Marks :@ViewData["Marks"]
     </div>

Here we have displayed the value. Now we have done run the application to check the output.


Now click on link. After this we will hit the break point. So here check the we are getting request querystring value.



Here is the url



Here is the final output.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

1 comment:

  1. Good Post.
    Thank you Sir... you are realy help full.

    ReplyDelete

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top