在执行操作后查看不更新内容文本

时间:2016-01-01 18:00:01

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

我使用ajax将字符串数据传递给名为StockData的MVC控制器:

...

mypostrequest.open("POST", "/home/stockData", true)
mypostrequest.setRequestHeader("Content-type", "application/json")
mypostrequest.send(json)

MVC Controller Action:

[HttpPost]
        [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        public ActionResult StockData(StockData model)
        {
            ModelState.Clear();
            using (EFDbContext db = new EFDbContext())
            {
                    foreach (var item in model.Items)
                    {
                        var company = db.Company.FirstOrDefault(x => x.Code == item.Code);
                        if (company != null)
                        {
                            db.Stock.Add(new Stock()
                                {
                                    Date = model.PublicationDate,
                                    CompanyID = company.CompanyID,
                                    Company = company,
                                    Price = item.Price
                                });
                        }
                    }
                    this.TerminateStock(db);
            }
            return PartialView(model);
        }

@using StockExchange.WebUI.Models
@model StockData
@{
    ViewBag.Title = "Stocks";
}


<table>
    @foreach (var item in Model.Items)
    {
        <tr>
             <td>@Model.PublicationDate</td>
            <td>@item.Name</td>
            <td>@item.Price</td>
        </tr>
    }
</table>

我不明白我做错了什么。在调试上面的代码时,数据成功填充了正确的数据,但在执行操作后,StockData没有任何变化(数据正确传递给View)。我很感激你的帮助

0 个答案:

没有答案