0

I have the code as below. When I run the code, I could see all the data in the ViewBag variables. But while rendering on the browser, I see the blank page. What could be the reason? Is there anything wrong in the code? Please help me. Thank you.

// Controller Code

 public class BlockController : Controller
  {

    [Authorize]
    [HttpGet]
    public ActionResult Index()
    {
        BlockViewModel model = new BlockViewModel();

        ViewBag.Facilities = new List<FieldProcessingFacility>();
        ViewBag.Data = new List<BlockField>();
        ViewBag.BlockFields = new List<BlockField>();
        ViewBag.Tanks = new List<FacilityTank>();
        ViewBag.Facility = new List<FieldProcessingFacility>();
        ViewBag.Blocks = model.GetAllBlocks();
        ViewBag.BlockPartial = new Epsa.Client.ViewModel.Master.Blocks.BlockViewModel();
        ViewBag.BlockField = new Epsa.Client.ViewModel.Master.Blocks.BlockViewModel();
        ViewBag.BlockFacility = new Epsa.Client.ViewModel.Master.Blocks.BlockFacilityViewModel();
        ViewBag.BlockTanks = new Epsa.Client.ViewModel.Master.Blocks.BlockTanksViewModel();
        return View(model);
    }


    [HttpPost]
    public PartialViewResult GetDetailsOfBlock(long blockID)
    {
        // To get fields

        BlockFacilityViewModel bkvm = new BlockFacilityViewModel();
        var fields = bkvm.BlockFieldList(blockID);
        ViewBag.Data = fields;

        // To get facilities
        BlockViewModel bvm = new BlockViewModel();
        var facilities = bvm.GetFacilitiesByBlock(blockID);
        ViewBag.Facility = facilities;

        // To get Tanks
        BlockViewModel blockModel = new BlockViewModel();
        var fieldtanks = blockModel.GetTanksByBlockID(blockID);
        ViewBag.Tanks = fieldtanks;

        BlockSingleViewModel blockSingleModel = new BlockSingleViewModel();
        ViewBag.Types = blockSingleModel.GetBlockTypes();


        //return RedirectToAction("Index");
        return PartialView("_PartialBlock");
    }
}

// My Partial View

@model Epsa.Client.ViewModel.Master.Blocks.BlockViewModel

<div class="main mainDivPad">
<div class="col-lg-12" id="panel" style="padding: 0 !important">
    <div class="panel panel-primary">
        @*       Fields        *@
        <div class="panel-heading">
            <h1 class="panel-title" style="color: white">Fields & Tanks</h1>
        </div>
        <div class="row margintop20">
            <div class="col-lg-4 col-lg-offset-4">
                <div class="col-lg-8">
                    @Html.Label("Add Field Name")
                    <input type="text" id="fname" class="form-control dropDownLabel" placeholder="field Name" />
                </div>

                <div class="col-lg-4" style="margin-top: 30px">
                    <button type="button" class="btn btn-primary" id="Button1" onclick="saveFields()">Add</button>
                </div>
            </div>

            <div class="table-responsive col-lg-12 margintop20">
                <table class="table table-bordered table-hover" id="myTableDataField">
                    <thead>
                        <tr>
                            <th>Field Name</th>
                            <th style="width: 5%;">Edit</th>
                            <th style="width: 5%;">Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            var fielddata = ViewBag.Data as List<Epsa.Models.BlockField>;
                            foreach (var item in fielddata)
                            {
                            <tr>
                                <td>@item.Name</td>
                                <td>
                                    <button type="button"class="btn btn-md btn-primary newblock" id="editField"  value="@item.ID" onclick="getField(this)"><span class="glyphicon glyphicon-edit"></span></button>
                                </td>
                                <td>
                                    <button type="button"class="btn btn-md btn-primary newblock" value="@item.ID" onclick="deleteField(this)"><span class="glyphicon glyphicon-trash"></span></button>
                                </td>
                            </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>

            @*      Facilities       *@

            <div class="col-lg-12">
                <div class="panel panel-primary">

                    <div class="col-lg-3 col-lg-offset-1 margintop20">
                        @Html.Label("Field Name")
                        @Html.DropDownListFor(m => m.BlockFieldID, new SelectList(ViewBag.Data as List<Epsa.Models.BlockField>, "ID", "Name"), "--Select--", new { @class = "form-control dropDownLabel", @id = "fcFID" })
                    </div>

                    <div class="col-lg-3 margintop20">
                        @Html.Label("Add Facility Name")
                        <input type="text" id="fcName" class="form-control dropDownLabel" placeholder="Facility Name" />
                    </div>

                    <div class="col-lg-3 margintop20">
                        @Html.Label("Facility Type")
                        <select class="form-control dropDownLabel" id="fID">
                            <option value="">--Select--</option>
                            <option value="1">CPF</option>
                            <option value="2">FPF</option>
                        </select>
                    </div>

                    <div class="col-lg-2" style="margin-top: 50px">
                        <button type="button" class="btn btn-primary" id="facilityAddEdit" onclick="saveFieldFacility()">Add</button>
                    </div>

                </div>
            </div>

            <div class="table-responsive col-lg-12 margintop20">
                <table class="table table-bordered table-hover" id="myTableDataFacility">
                    <thead>
                        <tr>
                            <th>Facility Name</th>
                            <th>Facility Type</th>
                            <th style="width: 2%;">Edit</th>
                            <th style="width: 2%;">Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        @{
                            var facilitydata = ViewBag.Facility as List<Epsa.Models.FieldProcessingFacility>;
                            if (facilitydata.Count != 0)
                            {
                                foreach (var item in facilitydata)
                                {
                                    String type = "";
                                <tr>
                                    <td>@item.Name</td>
                                    @if (item.TypeID == 1)
                                    {
                                        type = "CPF";
                                    }
                                    else
                                    {
                                        type = "FPF";
                                    }
                                    <td>@type</td>
                                    <td>
                                        <button type="button"class="btn btn-md btn-primary newblock"  value="@item.ID" onclick="getFacility(this)"><span class="glyphicon glyphicon-edit"></span></button>
                                    </td>
                                    <td>
                                        <button type="button"class="btn btn-md btn-primary newblock" id="@item.BlockFieldID" value="@item.ID" onclick="deleteFacility(this)"><span class="glyphicon glyphicon-trash"></span></button>
                                    </td>
                                </tr>
                                }
                            }
                        }
                    </tbody>
                </table>
            </div>

            @*            Tanks            *@


            <div class="main col-lg-12" style="padding-top: 20px;">
                <div class="panel panel-primary">
                    <div class="col-lg-12 col-lg-offset-1">
                        @* <div class="col-lg-3">
                                                        @Html.Label("Field")
                                                        @Html.DropDownListFor(m => m.BlockFieldID, new SelectList(Model.BlockFieldsList, "ID", "Name"), "--Select--", new { @class = "form-control dropDownLabel", @id = "tankFID" })
                                                    </div>*@

                        <div class="col-lg-3 margintop20">
                            @Html.Label("Field Name")
                            @Html.DropDownListFor(m => m.BlockFieldID, new SelectList(ViewBag.Data as List<Epsa.Models.BlockField>, "ID", "Name"), "--Select--", new { @class = "form-control dropDownLabel", @id = "tankFID" })
                        </div>

                        <div class="col-lg-3 margintop20">
                            @Html.Label("Tank Name")
                            <input type="text" id="tname" class="form-control" placeholder="Tank Name" />
                        </div>
                        <div class="col-lg-3 margintop20">
                            @Html.Label("Capacity")
                            <input type="text" id="capa" class="form-control" placeholder="Capacity" />
                        </div>
                        <div class="col-lg-2" style="margin-top: 45px">
                            <button type="button" class="btn btn-primary" style="clear: right !important" onclick="saveFieldsTank()">Add</button>
                        </div>
                    </div>

                    <div class="table-responsive col-lg-12" style="padding-top: 20px;">
                        <table class="table table-bordered table-hover" id="myTableData">
                            <thead>
                                <tr>
                                    <th>Facility Name</th>
                                    <th>Tank</th>
                                    <th>Capacity</th>
                                    <th style="width: 2%;">Edit</th>
                                    <th style="width: 2%;">Delete</th>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    var tankdata = ViewBag.Tanks as List<Epsa.Models.FacilityTank>;
                                    if (tankdata.Count != 0)
                                    {
                                        foreach (var itemvalue in tankdata)
                                        {
                                            if (itemvalue.IsDeleted == 1)
                                            {
                                            }
                                            else
                                            {
                                        <tr>
                                            <td>@itemvalue.Name</td>
                                            <td>@itemvalue.Volume</td>
                                            <td>
                                                <button type="button"class="btn btn-md btn-primary newblock" value="@itemvalue.ID" id="editTankData" onclick="editTankValue(this)"><span class="glyphicon glyphicon-edit"></span></button>
                                            </td>
                                            <td>
                                                <button type="button"class="btn btn-md btn-primary newblock" id="@itemvalue.ID" value="@itemvalue.ID" onclick="deleteTank(this)"><span class="glyphicon glyphicon-trash"></span></button>
                                            </td>
                                        </tr>
                                            }
                                        }
                                    }
                                }
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

3
  • Why in the world are you using ViewBag when you have a model. And what is that partial view -Index.cshtml or _PartialBlock.cshtml? Commented Dec 13, 2015 at 6:48
  • @StephenMuecke _PartialBlock is the Partial View. I used the strongly typed model for all dropdowns and all the fields. I retrieved the data from db with the single controller call and I stored them in ViewBag variables to use in the View. Isn't that the proper standard? Commented Dec 13, 2015 at 6:54
  • Absolutely not (use a view model and strongly bind to your view model properties using the HtmlHelper methods). But where are you expecting to see this view? What is the point of the Index() method you have shown - its seems unrelated to your question? And how are you posting data to your GetDetailsOfBlock() that return this partial view? Commented Dec 13, 2015 at 6:59

1 Answer 1

1
  1. You must call PartialView function with BlockViewModel type argument. in this time your partial argument appears empty.

enter image description here

return PartialView("_PartialBlock",blockModel);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.