MVC c#controller返回视图()

时间:2012-09-28 05:17:40

标签: asp.net-mvc

下面是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Models = We.Models;
using We.BAL;
using System.Globalization;
using System.IO;
using System.Text;
using System.Web.Helpers;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;
using System.Web.Routing;
using System.Web.Security;
using PagedList;
using We.Models.ViewModels;
using We.Models.Interface;
using We.Models.DBData;
using We.Models.Repository;
using System.Data.Sql;
using System.Data.Query;
using System.Data.SqlClient;  

namespace We.Controllers
{
    public class ClientEnquiryController : Controller
    {
      private Models.Interface.IPolicyService _repository;  
      private Models.Repository.PolicyServiceRepository clientenqRepository;    

      public ClientEnquiryController()
           : this(new Models.Repository.PolicyServiceRepository())
      { 
      }

      public ClientEnquiryController(Models.Interface.IPolicyService repository)
      {
        _repository = repository;
      }

      public ActionResult MasterView( string PolicyNo, string carrierCode, string sPol, string languageCode)
      {
        carrierCode = "2";
        sPol = "502-0877220";
        languageCode = "eng";
        return View(_repository.policymaster(carrierCode, sPol, languageCode));            
      }

从我的代码我做这样的回报:

return View(_repository.policymaster(carrierCode, sPol, languageCode));

如果我想在同一时间返回包含多个语句的视图怎么样?例如:

_repository.policymaster(carrierCode, sPol, languageCode);
_repository.policyAgent(carrierCode, sPol, languageCode);

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:0)

我认为您可以从使用两个返回对象建模视图中受益。例如,

public class MasterViewVM
{
    public PolicyMaster {get; set;}
    public PolicyAgent {get; set;}
}

然后返回包含数据实体的视图模型:

public ActionResult MasterView(string PolicyNo, 
    string carrierCode, string sPol, string languageCode)
    {
        carrierCode = "2";
        sPol = "502-0877220";
        languageCode = "eng";
        MasterViewVM model = new MasterViewVM
        {
           PolicyMaster =_repository.policymaster(carrierCode, sPol, languageCode),
           PolicyAgent = _repository.policyAgent(carrierCode, sPol, languageCode)
        };
       return View(model);
    }

另一种可能性是使用儿童行动。参见

http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx