0

I do have a textbox and a submit button. All I have to do is to get the records based on the date provided and when a get request is made I just want to display a textbox and button. For Post request I want to check the date matches with the record and want to display the data within same view. How is that possible. I am having the view as

@model IEnumerable<ShopOnline.Models.Order>


<script type="text/javascript">
$(function () {
    $("#Date").datepicker({dateFormat:"dd/mm/yy"});
});
</script>
@using(Html.BeginForm())   
{
<table>
<tr>
    <td>Enter Date</td>
    <td>@Html.TextBox("Date")</td>       
    <td><input type="submit" value="Submit" /></td>
</tr>
</table>
}
<table border="1">
<thead>
    <tr>
        <td>Order</td>
        <td>Product Name</td>
        <td>Quantity</td>
        <td>Amount</td>
        <td>Price</td>
        <td>Date</td>
    </tr>
</thead>
<tbody>
    @foreach(var item in Model)
    {
<tr>
    <td>Select Date</td>
    <td>@item.Order_Id</td>
    <td>@item.Product_Name</td>
    <td>@item.Quantity</td>
    <td>@item.Amount</td>
    <td>@item.Order_Date</td>
</tr>
    }
    </tbody>

Here is the controller Action Method

 public ActionResult Admin()
    {
        return View(db.Orders.ToList());
    }
    [HttpPost]
    public ActionResult Admin(DateTime Date)
    {
        var record = db.Orders.Where(x => x.Order_Date ==Date).ToList();
        return View(record);
    }

Now here the problem is I will get all the records displayed if I perform GET Request and I only want to display a textbox and button on GET request and while if I perform a POST Request I want to get list of records in the same view with a textbox and button. So can Partial View be applied here and how will that work

tereško
  • 58,060
  • 25
  • 98
  • 150
Zaker
  • 537
  • 16
  • 30

1 Answers1

0

My controller code to access partial view

public ActionResult ItemsPartialView()
{
    List<Item> inventoryDetails = new List<Item>();
    return PartialView("ItemsView", inventoryDetails);
}

My Js

 $('#ItemView').on('click', function () {
    $.ajax({
            url: '@Url.Action("ItemsPartialView")',
            type: 'GET',
            success: function (result) {
                $('#ItemView').html(result);
            }
        });
    });

My Orginal View

<h4 > MY orginal View </h4>

<div id="ItemView">
    @Html.Partial("ItemsView", new Item())
</div>

Partial View : The partial View fileName is ItemsView

@model WebSite.Models.Item
@{
    ViewBag.Title = "ItemsView";
 }

<div>
   Hai this is my partial view
</div>
Aravindan
  • 855
  • 6
  • 15