0
//Here is my View
 @using 
 (Html.BeginForm("SearchUser", "User", FormMethod.Get))
  {
      <input type="text" id="keyText">
      <input type="submit" value="Search" class="btn btn-success btn-lg" />
  }

In my controller I am having a method for SearchUser -

[HttpGet]
public async Task<IActionResult> SearchUser ([FromQuery] string keyText)
{
    SearchUsersCommandAsync command = new SearchUsersCommandAsync
    {
        Key = keyText
    };

    var response = await new SearchUsersHandler(_db).Handle(command);
    return View("Detail", response);
}

However when i receive the request KeyText always null. Whats wrong I am doing here?

1
  • Your input needs a name attribute - name="keyText" in order to send a its value to the controller Commented Aug 22, 2016 at 9:08

1 Answer 1

1

Try this

<input type="text" id="keyText" name="KeyText">

add the name attribute to your input with same name as what you have use parameter in your controller method

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

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.