weixin_33712987 2016-04-13 11:18 采纳率: 0%
浏览 3

我看不到视图2

I want also call view1 and view2 methods.but it does not work.the Method "SubmitMyData" works properly and return the views for my ajax call .after run i expected the execution (for example )view2. In this example i must see view2

[System.Web.Mvc.Route("Home/SubmitMyData/")]
[System.Web.Http.HttpPost]
public ActionResult SubmitMyData([FromBody]MyParamModel mydata)
{             
    if (mydata.Prop1.Equals("1"))
    {
        view1();
        return View("view1");
    }
    else
    {
        view2();
        return View("view2");
    }            
}

here is the bodies of views methods

public ActionResult view1()
{
    ViewBag.Title = "view1";
    return View();
}

public ActionResult view2()
{
    ViewBag.Title = "view2";
    return View();
}

and here is my ajax call (if necessary to see)

$('#Buttonv').click(function () {
    var myData = {Prop1: "10", Prop2: ""}; 
    $.ajax({
        type: 'POST',
        data: myData, 
        url: '/Home/SubmitMyData',          
    })
    .success(function (data) {
        $('#lblmessage').html(data);
    })
    .error(function (xhr, ajaxoption, thrownError) {
        $('#lblmessage').html("moshkelo" + xhr + "ajaxoption= " + ajaxoption + " throwerror=" + thrownError);
    })
    //return false;
});
  • 写回答

1条回答 默认 最新

  • csdnceshi62 2016-04-13 11:21
    关注

    Replace your code view2(); with return RedirectToAction("view2");

    You need to redirect to a action than just executing it like a method.

    So your code would have to like below

    public ActionResult SubmitMyData([FromBody]MyParamModel mydata)
    {             
        if (mydata.Prop1.Equals("1"))
        {
            return RedirectToAction("view1");
            //return View("view1"); // not required
        }
        else
        {
           return RedirectToAction("view2");
           // return View("view2"); // not required
        }            
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。