[RESOLVED]How do I capture data sent to a page without having to specify a name?

Hello,

MVC5.  Very basic question here.

When I execute the following code from one webpage:

<form action="http://localhost:11704/Home/testpage" method="post">
  <input type="text" name="newdata" value="mydata" />
  <input type="submit" />
</form>

In the controller action shown below I can read the data Posted to the page ‘testpage’ because I know the name of name/value pair.

  <HttpPost>
  Function testpage(newdata As String) As ActionResult
    ViewBag.message = newdata
    Return View()
  End Function

But how would I read data posted to ‘testpage’ if I don’t know the name of the name/value pair?

Thanks.

Best Regards,

Alan

As cnuonline said you can iterate through the form collection for all the posted data. Curious why you need to do this. May be there are other ways to achieve what you want to accomplish.

Hi,

I thought someone might ask. 

I’m working through (obviously for the first time) an online payment posting process.  I want to have the critical financial data handled by a certified 3rd party. Part of that API is that after a payment is processed one can select from different ways to
receive the results of authentication.  One method is to have the results POSTed back to the URL of your choice.  So while that data is POSTed back, I haven’t found the name/value pairs in the documentation, so I thought I’d just pull it down and look.

Does that make sense?

Thanks for asking.

Best Regards,

Alan

For debugging purposes looking at the posted values make sense. But for the actual implementation, I recommend using an object which contains the posted values.

Also you can use fiddler for your scenario.

Hi,

FormCollection worked like a champ!  Thanks!  I might comment that the 2nd link provided by cnuonline seemed to show what I was looking for.  The 1st link appears to be relying on knowledge of the ‘key’ values.

And yes, re pprasannak’s point, this is only for debugging to find the keys so that for implementation the actual keys can be used.

Best Regards,

Alan

Leave a Reply