2017-05-25 55 views
0

我试图在我的视图中将链接复制到剪贴板。C#在我的视图中将链接复制到剪贴板

尝试了几个不同的职位,我在这里。 是否必须在我的模型中设置?

我想这段代码的链接复制到我的剪贴板

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

我的观点

@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())) 

我的模型

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(); 
    } 
} 
+0

你是不是想复制网址只或作为网页功能的一部分调试? – stomtech

+0

您的代码缺少结尾**)**。修复了'Clipboard.SetText(link,@(Url.Action (c => c.New())))'。 – stomtech

回答

2

Clipboard.SetText Method是从System.Windows.Forms的(在System.Windows.Forms.dll中)。
Windows窗体和ASP.NET MVC是完全不同的技术。

如果您试图在客户端复制某些内容,那么您可以尝试使用JavaScript或Flash。
看这个问题How do I copy to the clipboard in JavaScript?

如果你想调试你的行动网址,你可以尝试Debug.WriteLine

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