【问题标题】:Why my overload controller methods not hitting properly?为什么我的重载控制器方法没有正确命中?
【发布时间】:2016-01-29 11:06:15
【问题描述】:

我有一个名为PrintPatientConsent.aspx 的视图名称。我需要为两种类型调用它。

但是,默认情况下只调用默认操作方法。即使我传递了参数。

供您参考:

 [AcceptVerbs("GET")]
 public ActionResult PrintPatientConsent()
 {
   ----
 }

 [AcceptVerbs("GET")]
 [ActionName("PrintPatientConsent")] // i tried to pass action name
 public ActionResult PrintPatientConsent(int id)
 {
   ------
 }

Javascript:-

前代码:

url = '/Emr/Patients/PrintPatientConsent?Id=' + idd; //where i'm calling Parameterized actionmethod
TopUp.display(url)

谁能帮我找出解决方案..,谢谢。

【问题讨论】:

  • 你只需要一个方法——public ActionResult PrintPatientConsent(int? id)(你可以使用if(id.HasValue)检查一个值是否被传递
  • 删除actionname并尝试
  • @UbiquitousDevelopers- 我尝试删除动作名称..,即使它只调用默认动作方法..
  • 您是否尝试输入您的网址字符串,而不是Id,而是id
  • 你也可以试试这样的:stackoverflow.com/questions/17457710/…

标签: javascript c# jquery asp.net-mvc model-view-controller


【解决方案1】:

解决方案之一是

    public ActionResult PrintPatientConsent(int? id)
    {
        if(id == null) {
            // case A
        }
        else {
           // case B
        }
    }

也可以使用方法选择属性:The current request for action {0} on controller type {1} is ambiguous

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多