0

I'm trying to copy a link to the clipboard in my view.

Tried a few different posts and I'm here. Does it have to be set up in my model?

I want to copy the link this code makes to my clipboard

@(Url.Action<MillerElectricLearn.Areas.Instructor.Controllers.UserController>(c => c.New())

My view

@model User_Index_ViewModel

@{
AddBreadcrumb<HomeController>(c => c.Index(), "Home");

}
<div><a href="@(Url.Action<MillerElectricLearn.Areas.Instructor.Controllers.UserController>(c => c.New()))" class="organizationRegistration btn btn-default">Create Learner</a></div>

Clipboard.SetText(link, @(Url.Action<MillerElectricLearn.Areas.Instructor.Controllers.UserController>(c => c.New()))

My model

 public class User_Index_ViewModel :ViewModel
{
   // public User_Index_ViewModel(IDependencyResolver dependencyResolver, IRuntimeContextProvider contextProvider)
    public User_Index_ViewModel(IDependencyResolver dependencyResolver, IRuntimeContextProvider contextProvider)
        : base(dependencyResolver.Get<IDataAccessService>())
    {
       this.ContextProvider = contextProvider;
        this.DependencyResolver = dependencyResolver;
    }
    public IRuntimeContextProvider ContextProvider { get; set; }
    public IDependencyResolver DependencyResolver { get; set; }
    public List<User> TheInstructorsLearners { get; set; }


    public User CurrentUser { get; set; }
    protected override void PrepareForView()
    {
        base.PrepareForView();

        CurrentUser = DataAccessService.GetUser(ContextProvider.GetContext().User);

        this.TheInstructorsLearners = DataAccessService.Find<User>(x => x.OrganizationId == CurrentUser.OrganizationId).ToList();
    }
}
CsharpBeginner
  • 1,643
  • 7
  • 36
  • 63

1 Answers1

2

The Clipboard.SetText Method is from System.Windows.Forms (in System.Windows.Forms.dll).
Windows Forms and ASP.NET MVC are absolutely different technologies.

If you are trying to copy something on the client side then you can try to use javascript or flash.
Look at this question How do I copy to the clipboard in JavaScript?

If you are trying to debug your action URL, you can try Debug.WriteLine:

@{System.Diagnostics.Debug.WriteLine( Url.Action<MillerElectricLearn.Areas.Instructor.Controllers.UserController>(c => c.New())) );}
stomtech
  • 424
  • 3
  • 8