C# 当字符串值转到.net mvc方法时,它将变为null#

C# 当字符串值转到.net mvc方法时,它将变为null#,c#,asp.net-mvc,C#,Asp.net Mvc,大家好 **编辑** 我缩短了代码,因为它太多了tempdata从另一个页面获取一个值,在重定向到此页面后,我只使用它一次 &如果你回答a-1,我尝试了很多不起作用的东西 string abcd = ""; public ActionResult Index() { abcd = @Tempdata["type"].ToString(); //here i call a method to do stuff getStuff(); } public void getStuff() {

大家好
**编辑** 我缩短了代码,因为它太多了tempdata从另一个页面获取一个值,在重定向到此页面后,我只使用它一次 &如果你回答a-1,我尝试了很多不起作用的东西

string abcd = "";

public ActionResult Index()
{
abcd = @Tempdata["type"].ToString();

//here i call a method to do stuff 

getStuff();
}

public void getStuff()
{
  if (abcd.equals("WORK_PLZ"))
  {
     //stuff here
  }
}

我的问题在
getStuff()
abcd
的值是
null
&我不知道为什么。在调用该方法之前,我尝试传递一个静态值,如
OK
,但它不起作用

我犯了一个简单的错误,因为我感到困惑。 我有一个模型视图,它与视图通信以传递所有数据,但我没有将tempdata的值放在我保留为空的
abcd
中。 我不确定在
之前是否需要
@
,但即使没有它也可以工作 作为


索引操作方法需要返回类型!您在何处分配TempData?
abcd
为空,因为
TempData[“type”]
为空,这很简单。
model.abcd = @Temdpata["ahh"].ToString();
// & i left abcd decalred in method null THEREFORE Exception