MVC局部视图未显示会话变量

时间:2015-01-07 12:37:03

标签: asp.net-mvc asp.net-mvc-4

当我加载edit.cshtml视图时,会在控制器中设置会话[" Order_Number"]并传递给View。由于某种原因,此会话变量不会传递给partialview。

获取错误:名称' ordernumber'在当前上下文中不存在

Edit.cshtml

@{
    var ordernumber = (int)Session["Order_Number"];     
}


<div id="tabs">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tabs-1">General</a></li>
        <li><a href="#tabs-2">Item</a></li>
        <li><a href="#tabs-3">Total</a></li>       
    </ul>


    <div id="tabs-1">
        @{Html.RenderPartial("_Partial_General_Tab");}
    </div>

    <div id="tabs-2">
       @{Html.RenderPartial("_Partial_Item_Tab");}
    </div>

    <div id="tabs-3">
        Content for Tab 3 goes here.<br />        
    </div>

 </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#tabs").tabs();
        });
    </script>

_Partial_General_Tab.cshtml

@model Mvc5.Models.ORDERMetadata

@using (Html.BeginForm("Edit", "Order"))
{
    @Html.AntiForgeryToken()

    @Html.ValidationSummary(true)

    // Set New Order Number
    @Html.HiddenFor(model => model.Order_Number, new { @Value = ordernumber })    <====== Error Here!!!!!!


    <div class="panel panel-default">
        <div class="panel-body">

            <div class="row">
                <div class="col-lg-3">
                    @Html.LabelFor(model => model.Order_Type)
                </div>
                <div class="col-lg-9">
                    <div id="combo_OrderTypes"></div>
                    @Html.HiddenFor(model => model.Order_Type, new { id = "ordertype" })

                </div>
            </div>


           <button id="editorder" type="submit" class="btn btn-default">Save</button>
        </div>
    </div>

}

0 个答案:

没有答案