0

I have a querystring like this:

http://localhost:2563/Skill?Months=1,2,3,4,5,6,7,8,9,10,11,12&SelectedMonth=8&Year=2016,2017,2018&SelectedYear=2016&....

And I want to pass Months, SelectedMonth, Year, SelectedYear value into Index() of controller (Index is a function takes 0 argument). And another issue, after Index function completed, I want binding function (in javascript) to run to bind value into dropdownlist by the SelectedMonth, SelectedYear in querystring

Please help. This function helps access the Views by QueryString (not through my website) Many thanks.

2
  • 1
    What have you tried so far? StackOverflow is not a free coding site where you can jump on and ask for things to be done. Please show your work first so that we can collaborate. Commented Aug 16, 2016 at 12:07
  • Yeah, I just newbie and have to learn more, so ask is a best learning way I think. Thanks for your comment. I will try to answer as much as question I can to get collaborated. Commented Aug 16, 2016 at 12:17

3 Answers 3

1

First, the action name is wrong. you should use the following,

http://localhost:2563/index?Months=1,2,3,4,5,6,7,8,9,10,11,12&SelectedMonth=8&Year=2016,2017,2018&SelectedYear=2016&...

instead of

http://localhost:2563/Skill?Months=1,2,3,4,5,6,7,8,9,10,11,12&SelectedMonth=8&Year=2016,2017,2018&SelectedYear=2016&....

second, You need to pass some parameters. Here is how:

public ActionResult Index(List<int> Months,int SelectedMonth,List<int> Year, int Year)
{

}

remember to pass values as you wish to work with them. if you don't, you will face some error. use try catch block to prevent and handle exceptions.

You may also face exception accessing the web page. try to put optional parameter instead of using the above one.

 public ActionResult Index(List<int>? Months,int? SelectedMonth,List<int>? Year, int? Year)
    {

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

7 Comments

action name may be change by add new route redirect to index directly
he was talking about index action in the question. So, suggested him to use index.
I just use /Skill, it call index action.
ok got it :D . I thought you might be hitting it wrongly. btw, optional parameter would be used here. if not passed, it won't hurt the action to execute
I think it is better. And how to bind the dropdown list after index function is done.
|
0
public ActionResult Index(List<int> Months,int SelectedMonth,List<int> Year, int Year)
{

}

or use Reqest.QueryString

public ActionResult Index()
{
    var months=Reqest.QueryString["Months"];
    .
    .
    .

}

2 Comments

Index is a function takes 0 argument
you can use Request.QueryString
0

You need to get parameters from here HttpContext.Current.Request.QueryString

Comments

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.