字典作为参数传递时会丢失值? [英] Dictionary loses value when passed as a parameter?
问题描述
我正在使用MVC,在重定向到操作之前,我会填充一些值,在此期间,我的词典中的计数始终为0?
I am using MVC, I populate some values before redirecting to an action, During this my dictionary always has a count of 0?
我会在此之前检查计数通过,并且超过0,但通过另一侧时始终为0。
I check the count before it passes and its over 0 but always 0 when it comes through the other side.
我也传递了其他字符串值,但它们都通过了。
I pass other string values too but they all come through fine.
我的重定向至操作。
return RedirectToAction(
"APNewQuote",
new {
OENumber = "", QuoteNumber = "", ClaimNumber = ClaimNumber,
MotorBodyRepairer = "", VehicleRegistration = vRegistration,
vehicleMakeId = "", vehicleModelId = "", vehicleRangeId = "",
vehicleMakeModels = "", vehicleModelCode = "",
year = vYear, OEParts = OEParts }
);
我的操作结果接收到值。
My Action result receiving the values.
public ActionResult APNewQuote(string OENumber, string QuoteNumber, string ClaimNumber,
string MotorBodyRepairer, string VehicleRegistration, int? vehicleMakeId,
int? vehicleModelId, int? vehicleRangeId, string vehicleMakeModels,
string vehicleModelCode, int? year, Dictionary<string,string> OEParts )
有人可以告诉我如何避免这种情况。
Could someone please tell me how i can prevent this.
推荐答案
我认为字典没有序列化。如在此问题的答案中所述 如果您需要传递重定向后对操作有些复杂的对象,您可能要使用Session或TempData:
I think the dictionary doesn't get serialized. As explained in this question's answer If you need to pass in some-what complex objects to an action after a redirect, you probably want to use either a Session or TempData:
因此将字典保存到 TempData
或 Session
对象。
So save your dictionary into TempData
or the Session
object.
用法:
// save
TempData["myDictionary"] = OEParts;
// retrieve
var myDic = TempData["myDictionary"] as Dictionary<string,string>;
这篇关于字典作为参数传递时会丢失值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!