Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net mvc5中将值传递给路由_C#_Asp.net_.net_Asp.net Mvc - Fatal编程技术网

C# 在asp.net mvc5中将值传递给路由

C# 在asp.net mvc5中将值传递给路由,c#,asp.net,.net,asp.net-mvc,C#,Asp.net,.net,Asp.net Mvc,我的第一个控制器: public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create(personalInfoModel personalInfo) { if (ModelState.IsValid) { TempData["key"] = personalInfo.CNIC; PersonalInfoViewModel pivm

我的第一个控制器:

public ActionResult Create()
{
    return View();
}

[HttpPost]
public ActionResult Create(personalInfoModel personalInfo)
{
    if (ModelState.IsValid)
    {
        TempData["key"] = personalInfo.CNIC;

        PersonalInfoViewModel pivm = new PersonalInfoViewModel();
        pivm.AddNewRecord(personalInfo);

        return RedirectToAction("Create", "Experience", new { key = personalInfo.CNIC});
    }

    return View();
}
我的第二个控制器代码是:

public ActionResult Create(string key)
{
    if (filled == true)
    {
        TempData["alertMessage"] = "<script>alert('Fill it first!')</script>";
    }
    filled = true;
    return View(key);
}

[HttpPost]
public ActionResult Create(experiencesModel experiences, string key)
{
    filled = false;
    ExperiencesViewModel evm = new ExperiencesViewModel();
    evm.AddNewRecord(experiences, key);
    return View();

}
public ActionResult创建(字符串键)
{
if(filled==true)
{
TempData[“alertMessage”]=“警报('先填充!')”;
}
填充=真;
返回视图(键);
}
[HttpPost]
公共行动结果创建(体验模型体验,字符串键)
{
填充=假;
ExperienceViewModel evm=新的ExperienceViewModel();
evm.AddNewRecord(经验,关键);
返回视图();
}
我想将密钥从第一个控制器传递到第二个控制器,其中我面临错误:

未找到视图“42201-09007860-1”或其主视图,或者没有视图引擎支持搜索的位置。搜索了以下地点: ~/Views/Experience/42201-09007860-1.aspx ~/Views/Experience/42201-09007860-1.ascx ~/Views/Shared/42201-09007860-1.aspx ~/Views/Shared/42201-09007860-1.ascx ~/Views/Experience/42201-09007860-1.cshtml ~/Views/Experience/42201-09007860-1.vbhtml ~/Views/Shared/42201-09007860-1.cshtml ~/Views/Shared/42201-09007860-1.vbhtml


我如何解决这个问题?我需要澄清如何在控制器之间传递值

视图的第一个参数是要渲染的视图的名称。如果要使用基于约定的默认视图,则必须传递null。第二个参数是您可以传递模型的地方,该模型可能是您的

return View(null, key);


视图
的第一个参数是要渲染的视图的名称。如果要使用基于约定的默认视图,则必须传递null。第二个参数是您可以传递模型的地方,该模型可能是您的

return View(null, key);


我认为您没有完全理解
返回视图()
代码。以下是
View()
View(“视图名”)
之间的区别:

return View()
返回与操作方法和
返回视图(“视图名称”)
返回当前视图文件夹中指定的视图名称

在这一行:

return View(key);
您试图返回的视图的名称与
参数中提供的名称相同,这当然不起作用。如果要查看
创建
页面,只需将其更改为以下行:

return View("Create", key);

我认为您没有完全理解
返回视图()
代码。以下是
View()
View(“视图名”)
之间的区别:

return View()
返回与操作方法和
返回视图(“视图名称”)
返回当前视图文件夹中指定的视图名称

在这一行:

return View(key);
您试图返回的视图的名称与
参数中提供的名称相同,这当然不起作用。如果要查看
创建
页面,只需将其更改为以下行:

return View("Create", key);

RedirectToAction还有第二个重载,它接受一个对象而不是RouteValueDictionary。也许您的新{}被错误地识别为对象?尝试创建一个真正的RouteValueDictionary。RedirectToAction还有第二个重载,它接受一个对象而不是RouteValueDictionary。也许您的新{}被错误地识别为对象?尝试创建一个真正的RouteValueDictionary。