-1

I am getting error: object reference not set to an instance of an object in this line of code in my Controller class method:

var ChangeEmailUrl = Url.Action("ChangeEmailConfirmation", "ManageAccount");

My objective is to get a URL path to an action 'ChangeEmailConfirmation' in controller 'ManageAccount'. The string link returned by the Url.Action() method would be sent in an email.

Also, I would like to know if there is any other way to get URL link. Any light on solving this problem would be appreciated.

w_billa
  • 23
  • 1
  • 5

2 Answers2

0

If you wanted to get an absolute url (http://localhost:8385/MyController/DoThis):

  var ChangeEmailUrl = Url.Action("DoThis", "MyController",null,Request.Url.Scheme,null)

See also

Carsten Cors
  • 2,505
  • 2
  • 14
  • 21
-1

you can try with urlhelper or htmlhelper

Url Helper:

Contains methods to build URLs for ASP.NET MVC within an application.

Official doc:https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper(v=vs.118).aspx

HtmlHelper.GenerateLink Method:

Generates an HTML anchor element (a element) that links to an action method

https://msdn.microsoft.com/en-us/library/system.web.mvc.htmlhelper.generatelink(v=vs.118).aspx

Example:

https://stackoverflow.com/a/700357/3397630

Hope it was useful

Thanks

Karthik

Karthik Elumalai
  • 1,574
  • 1
  • 11
  • 12