1

1 - I generate a Link from a WebApi Controller passing two parameters with:

var URL = new Uri( Url.Link("Default", new { Controller = "Reset", Action = 
"ResetPassword",user = "AAAAA", hash = "HASHVALUE" }));

And I get this:

http://localhost:52494/Reset/ResetPassword?user=BBBBBBBB&hash=AAAAAAA

2 - I need to Read these two parameters and the Form as well.

So I have a controller Reset with a ResetPassword Action:

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

[HttpPost]
public ActionResult ResetPassword(Models.ResetUserModel user)
{
   var HASH = Request["hash"];     
   var id = Request["user"];
   return View();
}

And the cshtml file:

enter image description here

If I run this page and fill the form, I will be able to read the ResetUserModel, but if it has some parameter, the model comes null!!

What am I doing wrong here?

5
  • it seems like the link is a Get request, while you are waiting for a Post. Commented Jul 12, 2017 at 11:51
  • How to I get both? The forms values and the parameter ? The first view ResetPassword is just to load the page.The request is made through the button. Commented Jul 12, 2017 at 11:54
  • Have you tried like this public ActionResult ResetPassword(string user, string hash) Commented Jul 12, 2017 at 11:54
  • if I do this, where I would receive the form data?There's a Model there! Commented Jul 12, 2017 at 11:56
  • @LaxmanGite I did this, Request.Form["oldpassword"]; and I get the value! I was worried about the model, but I found this way! Thanks! Commented Jul 12, 2017 at 11:58

2 Answers 2

3

It seems like you haven't defined related parameters in your action because you are passing two parameters from URI :

user = "AAAAA", hash = "HASHVALUE"

var URL = new Uri( Url.Link("Default", new { Controller = "Reset", Action = 
"ResetPassword",user = "AAAAA", hash = "HASHVALUE" }));

So you have to define you action according to that like :

[HttpGet]
public ActionResult ResetPassword(string user, string hash)
{
   var user = user;     
   var hash = hash;

   return View();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of using a HttpPost try to use a Get method:

[HttpGet]
public ActionResult ResetPassword(string user, string hash)
{
   //populate the model with the user and hash values
   var model = new ResetUserModel();
   model.User = user;
   model.Hash = hash;
   return View(model);
}

You will be able to invoke the ResetPassword with your link:

http://localhost:52494/Reset/ResetPassword?user=BBBBBBBB&hash=AAAAAAA

2 Comments

the answer above worked! Like, when the ActionResult ResetPassword is called I need to have not just the parameter but the Form values too.. user,hash,oldPassword,password,repeat..
@NathielBarros I am glad that it worked for you, but if you want to pass the model to your view, you will need a proper implementation of the ResetPassword method. I have added a complete example. Cheers!

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.