我试图用参数调用一个动作结果,但它们都显示为null?
这是我的ActionLink:
@Html.ActionLink("Add", "APNewQuote", "APQuotes", new {OENum = Model.OENumber, QuoteNumber = Model.QuoteNumber, ClaimNumber = Model.ClaimNumber, MotorBodyRepairer = Model.MotorBodyRepairer, VehicleRegistration = Model.VehicleRegistration, VehicleMakeId = Model.VehicleMakeId, VehicleModelId = Model.VehicleModelId, VehicleRangeId = Model.VehicleRangeId}, new { @class = "btn btn-primary niceButton" })
在我的控制器中:
public ActionResult APNewQuote(string OENum, string QuoteNumber, string ClaimNumber, string MotorBodyRepairer, string VehicleRegistration, int? vehicleMakeId, int? vehicleModelId, int? vehicleRangeId)
{
//Do things with the variables passed in
APNewQuoteViewModel viewModel = new APNewQuoteViewModel
{
OENumber = OENumber,
QuoteNumber = QuoteNumber,
ClaimNumber = ClaimNumber,
MotorBodyRepairer = MotorBodyRepairer,
VehicleRegistration = VehicleRegistration,
VehicleMakeId = vehicleMakeId,
VehicleMakes = vehicleMakes,
VehicleModelId = vehicleModelId,
VehicleModels = vehicleModels,
VehicleRanges = vehicleRanges,
VehicleRangeId = vehicleRangeId,
Date = Date
};
return View(viewModel);
}
上面的方法用于初始显示视图,如果所有输入参数都为空,则它很好,但是当我再次调用动作Result时,我需要使用这些参数,因此它们不能为空。
我可以运行我的项目,当我点击我的动作链接时,我只是为了一切恢复null,它确实会移动到正确的方法。
答案 0 :(得分:0)
您可以尝试访问ike:Request.Params[0]
答案 1 :(得分:0)
确保以下MVC Helper代码生成带有查询字符串的链接
@Html.ActionLink("Add", "APNewQuote", "APQuotes", new {OENum = Model.OENumber,
QuoteNumber = Model.QuoteNumber, ClaimNumber = Model.ClaimNumber,
MotorBodyRepairer = Model.MotorBodyRepairer, VehicleRegistration =
Model.VehicleRegistration, VehicleMakeId = Model.VehicleMakeId,
VehicleModelId = Model.VehicleModelId, VehicleRangeId = Model.VehicleRangeId},
new { @class = "btn btn-primary niceButton" })
即
<a href="/APNewQuote/Add?OENum=val1&QuoteNumber=val2,etc">APQuotes</a>
然后,默认情况下,您的控制器方法应该能够为[HttpGet]
提供服务。如果您只使用[HttpPost]
修饰,请同时添加HttpGet
动词。
[HttpGet]
[HttpPost]
public ActionResult APNewQuote(string OENum, string QuoteNumber, string ClaimNumber, string MotorBodyRepairer, string VehicleRegistration, int? vehicleMakeId, int? vehicleModelId, int? vehicleRangeId)
{
}