0

In the controlle,r I have this code:

var result = Request.Form[0];

where result has a value of 123,test,12,45,12/23/2010...etc..

How can I store each value in one variable?

2
  • 2
    Could you explain a little more what you want to accomplish? Commented Jun 21, 2010 at 18:17
  • thanks David, now my result having the following (123,test,12,45,12/23/2010...etc..) now I need to sotre each value in one variable..thanks Commented Jun 21, 2010 at 18:18

3 Answers 3

1

This feels like "broken as designed," but:

string result = (string)Request.Form[0];
string []results = result.Split(',');
Sign up to request clarification or add additional context in comments.

Comments

1

I am not sure what you want to do maybe try this-

string str =Request.Form[0].Select(c=>c.FormFieldName).ToString();

ideally you should get values using the id -

       string valueforid=Request.Form["Id"].Tostring();

Comments

1

It sounds like you're asking to have each of those values stored in a variable. It's not clear, as the question is written, what your end goal is.

Consider simply accessing those values by their array position.

string[] myValues = Request.Form[0]
                              .ToString()
                              .Split(',', StringSplitOptions.RemoveEmptyEntries);

foreach (string value in myValues)
{
    //do something

}

or

string customerID = myValues[0];
string customerName = myValues[1];

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.