Sai*_*udo 12 .net c# asp.net-mvc controller
我有两个具有相同名称但具有不同方法签名的控制器操作.它们看起来像这样:
//
// GET: /Stationery/5?asHtml=true
[AcceptVerbs(HttpVerbs.Get)]
public ContentResult Show(int id, bool asHtml)
{
if (!asHtml)
RedirectToAction("Show", id);
var result = Stationery.Load(id);
return Content(result.GetHtml());
}
//
// GET: /Stationery/5
[AcceptVerbs(HttpVerbs.Get)]
public XmlResult Show(int id)
{
var result = Stationery.Load(id);
return new XmlResult(result);
}
Run Code Online (Sandbox Code Playgroud)
我的单元测试没有调用一个或另一个控制器动作的问题,但是我的测试html页面抛出了System.Reflection.AmbiguousMatchException.
<a href="/Stationery/1?asHtml=true">Show the stationery Html</a>
<a href="/Stationery/1">Show the stationery</a>
Run Code Online (Sandbox Code Playgroud)
需要改变什么来使这项工作?
Sch*_*ime 11
只要有一个像这样的方法.
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Show(int id, bool? asHtml)
{
var result = Stationery.Load(id);
if (asHtml.HasValue && asHtml.Value)
return Content(result.GetHtml());
else
return new XmlResult(result);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10647 次 |
最近记录: |