如何后提交返回一条讯息 [英] How to return back a message after a submit

查看:58
本文介绍了如何后提交返回一条讯息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code作为预期这是行不通的。我想有从控制器,并使用警报显示从控制器返回的值retrun。

  $('#变化)。对话框({
            的AutoOpen:假的,
            宽度:380,
            纽扣: {
                关闭:功能(){
                    $(本).dialog(亲密);
                },
                接受:功能(){
                    。VAR测试= $(#ChangePasswordForm)提交();
                    警报(测试);
                }
            }
        });

在我的控制器我想返回一个字符串

 的[AcceptVerbs(HttpVerbs.Post)
    公共字符串的ChangePassword(字符串名称)
    {
        VAR味精=酷!
如果(名字!= NULL)
返回味精;
                }

我怎么能这样做?


解决方案

 的[AcceptVerbs(HttpVerbs.Post)
  公众的ActionResult的ChangePassword(字符串名称)
  {
        VAR味精=酷!
        如果(名字!= NULL)
        {
            返回内容(味精,text / plain的);
        }
        其他
        {
            返回的内容(错误......,text / plain的);
        }
   }

I have the following code which is not working as expected. I want to have a retrun from the controller and using alert display the value returned from the controller.

 $('#change').dialog({
            autoOpen: false,
            width: 380,
            buttons: {
                "Close": function() {
                    $(this).dialog("close");
                },
                "Accept": function() {
                    var test = $("#ChangePasswordForm").submit();
                    alert(test);
                }
            }
        });

In my controller I want to return a string

  [AcceptVerbs(HttpVerbs.Post)]
    public string ChangePassword(string Name)
    {
        var msg = "Cool!";
if (name != null)


return msg;
                }

How can I do that?

解决方案

  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult ChangePassword(string Name)
  {
        var msg = "Cool!";
        if (name != null)
        {       
            return Content(msg, "text/plain");
        }
        else
        {
            return Content("Error...", "text/plain");
        }
   }

这篇关于如何后提交返回一条讯息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆