Asp.net mvc 4 Asp.NETMVC中的Facebook应用程序

Asp.net mvc 4 Asp.NETMVC中的Facebook应用程序,asp.net-mvc-4,model-view-controller,facebook-apps,Asp.net Mvc 4,Model View Controller,Facebook Apps,大家好,我用asp.net和mvc制作了一个facebook应用程序。我的问题是我不能在索引中使用不同的模型。我尝试了元组,但并没有被接受,我也尝试了更改MyAppUser模型,但再次并没有从程序中接受。我应该如何在同一索引中尝试不同的模型 public class MyAppUser { public string Id { get; set; } public string Name { get; set; } public string Email { get;

大家好,我用asp.net和mvc制作了一个facebook应用程序。我的问题是我不能在索引中使用不同的模型。我尝试了元组,但并没有被接受,我也尝试了更改MyAppUser模型,但再次并没有从程序中接受。我应该如何在同一索引中尝试不同的模型

  public class MyAppUser
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }

    [JsonProperty("picture")] // This renames the property to picture.
    [FacebookFieldModifier("type(large)")] // This sets the picture size to large.
    public FacebookConnection<FacebookPicture> ProfilePicture { get; set; }

}

您可以只使用一个Index(),但有许多选项可以选择如何绑定数据:

两款车型

    public ActionResult Index(MyAppUser appUser, NumberModel numberModel)
    {
        if (appUser != null)
        {
            // todo
        }
    }
一个共享视图模型

    public class ViewModel
    {
        public MyAppUser MyAppUser { get; set; }
        public NumberModel NumberModel { get; set; }
    }

    public ActionResult Index(ViewModel viewModel)
    {
        if (viewModel.MyAppUser != null)
        {
            // todo
        }
    }
两者的组合

    public class ViewModel
    {
        public MyAppUser MyAppUser { get; set; }
        public NumberModel NumberModel { get; set; }
    }

    public ActionResult Index([Bind(Prefix = "MyAppUser")]MyAppUser appUser, [Bind(Prefix = "NumberModel")]NumberModel numberModel)
    {
        if (appUser != null)
        {
            // todo
        }
    }

我认为,在您的情况下,使用shared ViewModel并检查ViewModel中的对象是否为空是最好的解决方案。

您可以只使用一个索引(),但您有许多选择如何绑定数据:

两款车型

    public ActionResult Index(MyAppUser appUser, NumberModel numberModel)
    {
        if (appUser != null)
        {
            // todo
        }
    }
一个共享视图模型

    public class ViewModel
    {
        public MyAppUser MyAppUser { get; set; }
        public NumberModel NumberModel { get; set; }
    }

    public ActionResult Index(ViewModel viewModel)
    {
        if (viewModel.MyAppUser != null)
        {
            // todo
        }
    }
两者的组合

    public class ViewModel
    {
        public MyAppUser MyAppUser { get; set; }
        public NumberModel NumberModel { get; set; }
    }

    public ActionResult Index([Bind(Prefix = "MyAppUser")]MyAppUser appUser, [Bind(Prefix = "NumberModel")]NumberModel numberModel)
    {
        if (appUser != null)
        {
            // todo
        }
    }

我认为,在您的情况下,使用共享ViewModel并检查ViewModel中的对象是否为空是最好的解决方案。

我不完全理解您的问题,您的索引视图中需要两个模型吗?显然MVC只接受一个,所以创建一个viewmodel并在其中使用两个不同的模型。我这样做了,但没有返回任何信息。我不完全理解您的问题,您需要在索引视图中使用两个模型吗?显然MVC只接受一个,所以创建一个viewmodel并在其中使用两个不同的模型。我这样做了,但没有返回任何结果