0

I want to send some data when user clicks on this link

<a asp-action="ViewOthersProfile">@question.Questionaire</a>

and this is my action method

[HttpGet]
public ViewResult ViewOtherProfile()
{
  return View("OtherProfile");
}

also,how we'll get it in action method. Thanks in advance

3
  • Use a query-string parameter. Commented Aug 3, 2022 at 17:19
  • like ?data="" but how to get this in action method? Commented Aug 3, 2022 at 17:21
  • ViewOtherProfile( [FromQuery( Name = "data" )] String? data = null ) Commented Aug 3, 2022 at 17:25

1 Answer 1

1
//Use asp-route-myData for your data and you can name it whatever you want.
//asp-route-myData2, asp-route-data, asp-route-dog, ... you got the point.
<a asp-action="ViewOthersProfile" asp-route-myData="test string">@question.Questionaire</a>

//Here you can get your data as a parameter. 
//However, the parameter name must be the last part of asp-route-myData. I mean 'myData'
[HttpGet]
public ViewResult ViewOtherProfile(string myData) 
{
  //And you can use myData whatever way you need
  var result = myData + "test2";
  return View("OtherProfile");
}
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.