无法在网络浏览器上看到视图?

时间:2016-07-05 08:40:09

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

我有一个页面,其中有一个html表,我使用java脚本和ajax来调用控制器操作 - "任务"通过模型点击这个html表的一行。我在我的任务操作中获得了这个模型值。

在任务操作中,我将其重定向到另一个控制器操作。另一个控制器操作是BOMItemCost,我的视图是BOMItemCost.cshtml。

我调试了它,我的调试器将进入视图,但最后我没有在我的网络浏览器上看到我的视图。

Html表和javascript代码:

<table class="TableID2" id="tblTask">
    <thead>
        <tr>
            <th>Task Id</th>
            <th>Task</th>
            <th>Raised</th>
            <th>Department</th>
            <th>Raised On</th>
            <th>Status</th>
        </tr>
    </thead>
        <tbody><tr>
            <td>1</td>
            <td>1</td>
            <td>Rahul</td>
            <td>Marketing</td>
            <td>28/06/2016 00:00:00</td>
            <td>False</td>
        </tr>
        <tr>
            <td>3</td>
            <td>1</td>
            <td>jitender</td>
            <td>Marketing</td>
            <td>30/06/2016 00:00:00</td>
            <td>False</td>
        </tr>
        <tr>
            <td>5</td>
            <td>1</td>
            <td>Jitender Singh</td>
            <td>Marketing</td>
            <td>07/02/2016 16:23:10</td>
            <td>False</td>
        </tr>
        <tr>
            <td>6</td>
            <td>1</td>
            <td>Jitender Singh</td>
            <td>Marketing</td>
            <td>07/04/2016 02:56:00</td>
            <td>False</td>
        </tr>

    </tbody>
</table>

<script type="text/javascript">
    taskdetail = [];
    $("#tblTask tr").click(function (tr) {
        debugger;
        var tableData = $(this).children("td").map(function () {
                    return $(this).text();
                }).get();
        taskdetail.push({
            taskid: tableData[0],
            tasktype: tableData[1],
            assignby: tableData[2],
            department: tableData[3],
            assignon: tableData[4],
            status: tableData[5],

        });
        debugger;

        var model = {
            taskdetail: taskdetail
        };
        $.ajax({
            url:'@Url.Action("Task", "Job")',
            type: "POST",
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({ data: model }),
            dataType:'json',
            success: function (data) {
                alert('Document Saved.');
            }
        });
    });

&#34;任务&#34; JobController中的操作是

    [HttpPost]
    public ActionResult Task(JobModel data)
    {
        List<TaskDTO> listoftaskdetail = new List<TaskDTO>();
        listoftaskdetail = data.taskdetail.ToList();


        return RedirectToAction("BOMItemCost", "Tasks", listoftaskdetail);
    }

&#34; BOMItemCost&#34; TasksController中的操作是

   [HttpGet]
   public ActionResult BOMItemCost(List<TaskDTO> listoftaskdetail)
   {
       return this.View();
   }

和BOMItemCost.cshtml是

<div id="container">
<div class="wrapper white-bg">
        <div class="col s12 m12 l12">
            <div class="border-light pad-md">
                <div class="heading24">BOM for Bidding</div>
                <form>
                    <input type="hidden" name="hiddenField" />
                    <div class="table_h1">

                        <table id="TableID1">
                            <thead>
                                <tr>
                                    <th>Sr. No.</th>
                                    <th>Item Code</th>
                                    <th>Description</th>
                                    <th>Qty Per Unit</th>
                                    <th width="10%">Price</th>
                                    <th>Total</th>

                                </tr>
                            </thead>
                            <tr>
                                <td>1</td>
                                <td>11234</td>
                                <td>Cap Capacitor</td>
                                <td>50</td>
                                <td class="editbox">400</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>1</td>
                                <td>11234</td>
                                <td>Cap Capacitor</td>
                                <td>50</td>
                                <td class="editbox">400</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>1</td>
                                <td>11234</td>
                                <td>Cap Capacitor</td>
                                <td>50</td>
                                <td class="editbox">400</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
                    @Html.TextArea("anshul")
                    </div>
                    <div class="clearfix"></div>
                    <div class="mar-sm-t pull-right">
                        <button class="btn waves-effect waves-light" type="submit" name="action">CANCEL</button>
                        <button class="btn waves-effect waves-light" type="submit" name="action">SEND TO MARKETING</button>
                    </div>
                </form>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>

我已经调试过了。我的编译器已经浏览了我的视图,但我无法在我的Web浏览器上看到我的视图。

1 个答案:

答案 0 :(得分:0)

由于您是从jquery调用您的操作,因此结果将始终返回到jquery方法。 实际上,&#34;数据&#34; &#34; BOMItemCost.cshtml&#34; ,一旦获得数据,你可以在页面的某个地方附加你想要显示新视图的地方..

 $.ajax({
        url:'@Url.Action("Task", "Job")',
        type: "POST",
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({ data: model }),
        dataType:'json',
        success: function (data) {
        //BOMItemCost.cshtml is coming in data
        //So bind data inside some div 
          $('#divResult').append(data);
            alert('Document Saved.');
        }
    });