变量无法获得正确的值Asp.net MVC

时间:2018-02-03 20:55:43

标签: c# asp.net asp.net-mvc

我有一个基于申请编号拉取的网页上的项目列表,现在我正在尝试使用存储过程中的申请编号和行号编辑每个项目,但是它表示没有提供line_num。当我提供行号时,它甚至在行号为1时返回。在调试中,我测试了行号是什么以及每个行号存在。如何获取要提供给存储过程的行号。

public ActionResult Edit(int id,Item item)
{
     IssueDAO dbData = new IssueDAO();

    getIssue.item.lineNum = item.lineNum;
    var studentList = dbData.GetIssueDetails(getIssue.requisitionNumber,item);

    return View(studentList);
}


public Issue GetIssueDetails(string requisitionNum,Item issueditem)
{
    Issue items = new Issue();

    SqlConnection TWCLOPConnect = new SqlConnection(ConfigurationManager.ConnectionStrings["TWCL_OPERATIONSConnectionString"].ConnectionString);

    SqlCommand cmd = new SqlCommand() ;
    SqlDataReader itemRdr;
    cmd.Connection = TWCLOPConnect;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "GetIssueDetails";
    cmd.Parameters.Add("@reqnum", SqlDbType.VarChar).Value = requisitionNum;
    cmd.Parameters.Add("@line_num", SqlDbType.Int).Value = issueditem.lineNum;



    try
    {
        TWCLOPConnect.Open();
        itemRdr = cmd.ExecuteReader();

        while (itemRdr.Read())
        {
            Item item = new Item();
            item.itemNumber = itemRdr.GetString(0);
            item.description = itemRdr.GetString(1);
            item.price = Convert.ToDouble(itemRdr[4]);
            item.quantity = Convert.ToDouble(itemRdr[2]);
            item.expense_account.index = itemRdr.GetInt32(3);
            item.lineNum = itemRdr.GetInt32(5);

            //items.Add(item);
        }
        itemRdr.Close();
    }
    catch (Exception ex)
    {

        throw ex;
    }


    return items;
}

查看

 <table>
    <tr>
       <th></th>
        <th class="col-md-4">Item Number</th>
        <th class="col-md-4">Item Description</th>
        <th class="col-md-4">Expense Account</th>

    </tr>


    @{
        if (@Model.items.Count > 0)
        {
            foreach (var issueditem in @Model.items)
            {
                <tr>
                    <td>@Html.DisplayFor(model => issueditem.lineNum)</td>
                    <td class="col-md-4">@issueditem.itemNumber</td>
                    <td class="col-md-4">@issueditem.description</td>
                    <td class="col-md-4">@issueditem.expense_account.getDescription</td>
                    <td class="col-
                    <td> @Html.ActionLink("Edit", "Edit", new { id= issueditem.lineNum}) </td>



                </tr>
            }

        }


    }

0 个答案:

没有答案