第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我們可以在RedirectToAction中將模型作為參數(shù)傳遞嗎?

我們可以在RedirectToAction中將模型作為參數(shù)傳遞嗎?

手掌心 2019-10-21 10:02:00
我想知道,有什么技術(shù)可以Model作為參數(shù)傳遞給RedirectToAction例如:public class Student{    public int Id{get;set;}    public string Name{get;set;}}控制者public class StudentController : Controller{    public ActionResult FillStudent()    {        return View();    }    [HttpPost]    public ActionResult FillStudent(Student student1)    {        return RedirectToAction("GetStudent","Student",new{student=student1});    }    public ActionResult GetStudent(Student student)    {        return View();    }}我的問(wèn)題-我可以在RedirectToAction中傳遞學(xué)生模型嗎?
查看完整描述

3 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊

使用TempData


表示僅在一個(gè)請(qǐng)求到下一個(gè)請(qǐng)求之間存在的一組數(shù)據(jù)


[HttpPost]

public ActionResult FillStudent(Student student1)

{

    TempData["student"]= new Student();

    return RedirectToAction("GetStudent","Student");

}


[HttpGet]

public ActionResult GetStudent(Student passedStd)

{

    Student std=(Student)TempData["student"];

    return View();

}

另一種方法 使用查詢字符串傳遞數(shù)據(jù)


return RedirectToAction("GetStudent","Student", new {Name="John", Class="clsz"});

這將生成一個(gè)GET請(qǐng)求,例如 Student/GetStudent?Name=John & Class=clsz


確保您要重定向到的方法已裝飾,[HttpGet]因?yàn)樯厦娴腞edirectToAction將發(fā)出帶有HTTP狀態(tài)代碼302 Found的GET請(qǐng)求(執(zhí)行url重定向的常用方法)


查看完整回答
反對(duì) 回復(fù) 2019-10-21
?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

只需調(diào)用不需要的動(dòng)作redirect to action或new模型的關(guān)鍵字即可。


 [HttpPost]

    public ActionResult FillStudent(Student student1)

    {

        return GetStudent(student1); //this will also work

    }

    public ActionResult GetStudent(Student student)

    {

        return View(student);

    }


查看完整回答
反對(duì) 回復(fù) 2019-10-21
  • 3 回答
  • 0 關(guān)注
  • 650 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)