Asp.net mvc 4 MVC:从控制器显示模式对话框

Asp.net mvc 4 MVC:从控制器显示模式对话框,asp.net-mvc-4,Asp.net Mvc 4,可以在控制器内显示模态对话框 例如: [HttpPost] public ActionResult Index(int contractType ) { if (contractType == 0 ) { return "SHOW MODALDIALOG BOX" with button "YES" and "NO" when click "YES" Refirect to nexe

可以在控制器内显示模态对话框

例如:

[HttpPost]
        public ActionResult Index(int contractType )
        {
            if (contractType == 0 )
            {
                return "SHOW MODALDIALOG BOX" with button "YES" and "NO" when click "YES" Refirect to nexe page, click "NO" stay in current page
            }
            else
            {
                return View();
            }
        }
感谢控制器(服务器)提供的答案,您无法显示弹出窗口。 您可以做的是返回视图。。。使用一些标志让视图显示javascript模式对话框

另一个选项是返回JSON而不是视图。。。并使用JS创建一个模态对话框。 然后。。。在clic YES上,您可以使用不同的参数调用相同的控制器操作(在您的示例中是“0”不同的参数),这次显示视图

示例:

[HttpPost]
    public ActionResult Registering( )
    {

        string RetResult =  new UserPermission().ValidateUser( Request["username"].ToString(), Request["password"].ToString() );

        if (!string.IsNullOrEmpty(RetResult)){
            ViewBag.MyErrorMessage = RetResult;
            return View(); //This will show the view named "Registering", but you can display any other.
//The ideal is display the same one where the user entered the user/pass.
        }
        else {
            return RedirectToAction("Index", "EvalMain"); 
        }
    }
@if(ViewBag.MyErrorMessage != null){
     //Display the error message
     //You can: display it in a div (without popup), you can show a javascript Alert(), or display a modal dialog.    
}
<div>@ViewBag.MyErrorMessage </div>
<script> alert(@ViewBag.MyErrorMessage);</script>
在您看来:

[HttpPost]
    public ActionResult Registering( )
    {

        string RetResult =  new UserPermission().ValidateUser( Request["username"].ToString(), Request["password"].ToString() );

        if (!string.IsNullOrEmpty(RetResult)){
            ViewBag.MyErrorMessage = RetResult;
            return View(); //This will show the view named "Registering", but you can display any other.
//The ideal is display the same one where the user entered the user/pass.
        }
        else {
            return RedirectToAction("Index", "EvalMain"); 
        }
    }
@if(ViewBag.MyErrorMessage != null){
     //Display the error message
     //You can: display it in a div (without popup), you can show a javascript Alert(), or display a modal dialog.    
}
<div>@ViewBag.MyErrorMessage </div>
<script> alert(@ViewBag.MyErrorMessage);</script>
要将其显示为DIV,只需执行以下操作:

[HttpPost]
    public ActionResult Registering( )
    {

        string RetResult =  new UserPermission().ValidateUser( Request["username"].ToString(), Request["password"].ToString() );

        if (!string.IsNullOrEmpty(RetResult)){
            ViewBag.MyErrorMessage = RetResult;
            return View(); //This will show the view named "Registering", but you can display any other.
//The ideal is display the same one where the user entered the user/pass.
        }
        else {
            return RedirectToAction("Index", "EvalMain"); 
        }
    }
@if(ViewBag.MyErrorMessage != null){
     //Display the error message
     //You can: display it in a div (without popup), you can show a javascript Alert(), or display a modal dialog.    
}
<div>@ViewBag.MyErrorMessage </div>
<script> alert(@ViewBag.MyErrorMessage);</script>
@ViewBag.MyErrorMessage
显示警报():

[HttpPost]
    public ActionResult Registering( )
    {

        string RetResult =  new UserPermission().ValidateUser( Request["username"].ToString(), Request["password"].ToString() );

        if (!string.IsNullOrEmpty(RetResult)){
            ViewBag.MyErrorMessage = RetResult;
            return View(); //This will show the view named "Registering", but you can display any other.
//The ideal is display the same one where the user entered the user/pass.
        }
        else {
            return RedirectToAction("Index", "EvalMain"); 
        }
    }
@if(ViewBag.MyErrorMessage != null){
     //Display the error message
     //You can: display it in a div (without popup), you can show a javascript Alert(), or display a modal dialog.    
}
<div>@ViewBag.MyErrorMessage </div>
<script> alert(@ViewBag.MyErrorMessage);</script>
警报(@ViewBag.MyErrorMessage);
要显示模式对话框,可以使用jQueryUI: 大致是这样的:

<div id="dialog" title="Error Registering">
<p>@ViewBag.MyErrorMessage</p>
</div>

<script>
    $(function() {
    $("#dialog").dialog();
    });
</script>

@ViewBag.MyErrorMessage

$(函数(){ $(“#dialog”).dialog(); });
谢谢您的回答。这个想法很简单。我正在运行eMemberShip WCF服务,该服务接受ussername和密码,并返回用户角色和权限。 如果用户名或密码不正确,服务返回错误字符串,然后我想用此错误字符串显示ModalDialog,如果不正确,则重定向其他页面

[HttpPost]
    public ActionResult Registering( )
    {

        string RetResult =  new UserPermission().ValidateUser( Request["username"].ToString(), Request["password"].ToString() );



        if (!string.IsNullOrEmpty(RetResult))
            return this.ModalDialog(RetResult);

        else
            return RedirectToAction("Index", "EvalMain"); 
    }

好的,但请告诉我更多关于你试图实现的逻辑。。。模态对话框的概念是什么?您在视图中显示了什么?谢谢您的回答。这个想法很简单。我正在运行eMemberShip WCF服务,该服务接受ussername和密码,并返回用户角色和权限。如果用户名或密码不正确,服务将返回错误字符串,然后我希望使用此错误字符串显示ModalDialog,而不是重定向到其他页面。