通过UploadValues POST重定向到Controller Action不起作用

时间:2015-04-22 13:05:51

标签: c# .net http-post

我应该从解决方案中的另一个项目调用邮件控制器的操作,Action看起来像这样:[控制器名称是 ServiceMailController ,操作名称是 SendNotification ,就像在来电者中一样。]

        [AllowAnonymous]
        [HttpPost]
        public ActionResult SendNotification(string MemberId, string Email, string Name, string RedirectUrl)
        {                
            bool isSent = false;
            try
            {


                Member member = MemberProvider.Instance.GetItem(ObjectId.Parse(MemberId));
                NotificationEmailModel model = new NotificationEmailModel(member);
                model.Email = Email;
                model.Name = Name;
                model.RedirectUrl = "http://example.com/" + member.UserName + "/calismalar";
                UIMailingManager.Instance.SendNotification(model);
                if(UIMailingManager.Instance.SendNotification(model).Success)
                {
                    isSent = true;
                    //comment
                }

            }            
            catch(Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
            return Json(isSent, JsonRequestBehavior.AllowGet);

以下是我的调用者代码,它使用WebClient.UploadValues通过使用" POST"将数据发布到上述操作。方法。

using (var wb = new WebClient())
                            {
                                var data = new NameValueCollection();
                                data["MemberId"] = item.Member.Id.ToString();
                                data["Email"] = item.Member.Email;
                                data["Name"] = item.Member.Name;
                                data["RedirectUrl"] = "http://example.com/" + item.Member.UserName + "/calismalar";                                  

                                var resp = wb.UploadValues("http://example.com/ServiceMail/SendNotification", "POST", data);

                            }

但是这给出了一个错误,根本没有详细解释。会是什么原因?

更新:Elmah的错误消息:

  

System.Web.HttpException(0x80004005):公共操作方法   ' sendNotification的'在控制器上找不到   ' HintKumasi.UI.Controllers.ServiceMailController&#39 ;.在   System.Web.Mvc.Controller.HandleUnknownAction(String actionName)at   System.Web.Mvc.Controller.b__1d(IAsyncResult的   asyncResult,ExecuteCoreState innerState)at   System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult的   asyncResult)at   System.Web.Mvc.MvcHandler.b__5(IAsyncResult的   asyncResult,ProcessRequestState innerState)at   System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`   1.CallEndDelegate(IAsyncResult的

     
    

asyncResult)at     System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,     布尔和放大器; completedSynchronously)

  

1 个答案:

答案 0 :(得分:0)

创建一个类并让方法接受其中一个对象:

$scope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl){
    // TODO What you want on the event.
});

控制器上的方法是从您的javascript获取一个对象,并且无法查看属性并使用这些属性保存参数。如果你告诉它期望和反对,它应该能够用传递的值解析和填充该对象。