如何在MVC 4视图中显示来自jsonresult的数据

时间:2014-01-16 07:17:34

标签: asp.net-mvc-4 jsonresult

如何在控制器上将jsonresult的数据显示到我的View?

请提供有关如何在视图上显示它的步骤。我是开发MVC4应用程序的新手。

以下是我的行动代码:

public ActionResult IndexChange(string ProposalID)
    {
        PurchaseOrderViewModel po;
        int proposalId = 0;

        proposalId = Convert.ToInt32(Session["ProposalID"]);
        int ID = Convert.ToInt32(Session["InstitutionID"]);

        List<Institution> lstInstitution = new List<Institution>();

        lstInstitution = db.Institutions.Where(x => x.InstitutionID == ID).ToList();

        List<NewProposal> lstPropospal = new List<NewProposal>();
        lstPropospal = db.NewProposal.Where(x => x.ProposalID == proposalId).ToList();

        ViewBag.Proposal = new SelectList(db.NewProposal.Where(x => x.Status.StatusID == 3), "ProposalID", "ProposalCode");

        var model = new PurchaseOrderViewModel
        {
            Institution = lstInstitution,
            Proposal = lstPropospal
        };

        return Json(model, JsonRequestBehavior.AllowGet);
    }

1 个答案:

答案 0 :(得分:0)

为什么要将其作为json发送...直接在您的视图return View(model)

中发送

在视图中导入您的模型,例如@model PurchaseOrderViewModel