Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 4 如何返回带有ActionLink的模型?_Asp.net Mvc 4_Model_Actionlink - Fatal编程技术网

Asp.net mvc 4 如何返回带有ActionLink的模型?

Asp.net mvc 4 如何返回带有ActionLink的模型?,asp.net-mvc-4,model,actionlink,Asp.net Mvc 4,Model,Actionlink,我试图在视图中获取一个模型并将其传递给另一个控制器,但当传递给另一个控制器时,该模型为null 控制器-在此,我将模型发送到视图中进行渲染: [HttpPost] public PartialViewResult Index(ReportesTabularesViewModel ModeloInput) { GetDatosTabularReportInput input = new GetDatosTabularReportInput { IdSensor

我试图在视图中获取一个模型并将其传递给另一个控制器,但当传递给另一个控制器时,该模型为null

控制器-在此,我将模型发送到视图中进行渲染:

   [HttpPost]
    public PartialViewResult Index(ReportesTabularesViewModel ModeloInput)
    {
        GetDatosTabularReportInput input = new GetDatosTabularReportInput { IdSensor = ModeloInput.sensor, FechaInicio = ModeloInput.FechaInicio, FechaFinal = ModeloInput.FechaFinal };
        ReportesTabularesViewModel Modelo = new ReportesTabularesViewModel();
        var Lista = new CaelusReporting.Datos.DatosApp().GetDatosTabularReport(input);

        var s = Modelo.Sensores;

        ViewBag.Sensores = s;
        Modelo.Datos = Lista.GroupBy(x => x.Fecha).Select(y => new DatosViewModel
        {
            Fecha = y.Key,
            EstacionSensorSensorNombre = y.First().EstacionSensorSensorNombre,
            Datos = y
        }
            );

        ViewBag.Modelo = ModeloInput;
        return PartialView(Modelo);
    }
视图:

@model CaelusReporting.Web.Models.ViewModels.Datos.ReportesTabularesViewModel
@{
ViewData[“temp”]=ViewBag.Modelo;
ViewBag.Title=Model.Datos.Select(y=>y.EstacionSensorSensorNombre).FirstOrDefault();
列表传感器=视图包。传感器;
}
@使用(Ajax.BeginForm(“Index”,新的AjaxOptions{UpdateTargetId=“Update”,HttpMethod=“POST”,InsertionMode=InsertionMode.Replace}))
{
传感器:
@foreach(传感器中的var项,其中(x=>x.estado==true))
{
@项目名称
}
伊尼西奥酒店
@Html.TextBoxFor(m=>m.FechaInicio,null,新的{type=“datetime local”,style=“最大宽度:235px;最大高度:20px”})
最终版:
@Html.TextBoxFor(m=>m.FechaFinal,null,新的{type=“datetime local”,style=“最大宽度:235px;最大高度:20px”})
}

您不能在请求(操作)之间传递ViewData。您需要以某种方式序列化数据,例如在查询中。您可以使用
RouteValueDictionary
执行此操作

您需要为action
ActionResult ExportReport(string DocType)
创建模型,如下所示:

public class ExportReportModel
{
    public string DocType {get; set;}
    // all fields which you required from ReportesTabularesViewModel
}
然后您的操作将如下所示
ActionResult ExportReport(ExportReportModel)
,您可以呈现这样的链接:

<a href="@Url.Action("ExportReport", "Reportes", new RouteValueDictionary(new ReportesTabularesViewModel{/*initialize object*/}))">Get  Report in PDF</a>

您也可以使用匿名对象,但如果您有3个以上的参数,我将以某种结构组织这些参数