尝试在MVC中的proc中获取键值传递 [英] Trying to get key value pass in the proc in mvc
本文介绍了尝试在MVC中的proc中获取键值传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的一个控制器中有一个名为 Index_shift
的操作方法:
I have an action method, called Index_shift
inside one my controller:
public ActionResult Index_shift()
{
ViewBag.shift_details = new SelectList(Getshift_details(),"ShiftId","ShiftVal");
return View();
}
Getshit_details
实现:
private List<shift_details> Getshift_details()
{
List<shift_details> shift_detail = new List<shift_details>();
shift_detail.Add(new shift_details { ShiftId = 0, ShiftVal = "Select" });
shift_detail.Add(new shift_details { ShiftId = 1, ShiftVal = "A" });
shift_detail.Add(new shift_details { ShiftId = 2, ShiftVal = "B" });
shift_detail.Add(new shift_details { ShiftId = 3, ShiftVal = "C" });
shift_detail.Add(new shift_details { ShiftId = 4, ShiftVal = "G" });
return shift_detail;
}
从以下视图部分调用该动作:
The action is called from the following view section:
@using (Html.BeginForm("Index_shift", "Scm_Mod_Sug", FormMethod.Post))
{
<div>
@Html.DropDownList("shift_details", ViewBag.shift_details as SelectList, new { Class = "form-control selectpicker show-tick" })
<input id="btnLogin" type="submit" value="Submit" class="btn btn-primary btn-block" />
</div>
}
http方法的返回值是我传递的值( 0、1、2、3、4 ),而不是移位值( Select,A,B,C,D,G ).
The return value of the http method is the value, which I pass (0, 1, 2, 3, 4), not the shift value (Select, A, B, C, D, G).
与数据库通信的代码:
public ActionResult Index_shift(FormCollection form)
{
string shift_details = form["shift_details"];
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["ABC"].ToString());
try
{
conn.Open();
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.CommandText = "pd01";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("V_SHIFT", OracleDbType.Varchar2).Value = shift_details;
}
//...
}
我在班次详细信息中得到的值是1.我想传递值"1"并返回"A".
I am getting the value 1 in the shift details. I want to pass value '1' and receive 'A' in return.
任何想法我如何实现的,都受到高度赞赏.
Any idea how can I achieve it are highly appreciated.
推荐答案
使用
new SelectList(ViewBag.shift_details, "ShiftId", "ShiftVal ")
代替
ViewBag.shift_details as SelectList
这篇关于尝试在MVC中的proc中获取键值传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文