2017-05-26 71 views
1

我正在创建一组视图组件,它们表示不同视图上的过滤器。目前为止他们工作得很好,但我不了解我正在经历的这种行为。具有可选参数的ViewComponent

如果我使用声明两个InvokeAsync:

public async Task<IViewComponentResult> InvokeAsync(string name) 
public async Task<IViewComponentResult> InvokeAsync(string name, string title) 

然后我得到这个:

Error: View component 'MyViewComponent' must have exactly one public method named 'InvokeAsync' or 'Invoke'.

但是,如果我做这样的事情,而不是:

public async Task<IViewComponentResult> InvokeAsync(string name, string title = "") 

然后出现这种情况:

<vc:my name="Hello" title="Hello"></vc:my> // Gets rendered 
<vc:my name="Hello" title=""></vc:my> // Gets rendered 
<vc:my name="Hello"></vc:my> // Doesn't call InvokeAsync 

那么,有没有可能使用默认参数?我不能使用这个模型(客户要求)

回答

0

this Github issue,它将被ASP.NET 2.2的核心来完成:

@Eilon modified the milestone: Backlog, 2.0.0-preview1 on Mar 22