问题与单一视图多个视图 [英] Issue with multiple views on single view

查看:122
本文介绍了问题与单一视图多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC,这是MVC的启动项目通过在略作修改的.NET Framework给出创建一个简单的页面。

I have create one simple page in MVC, which is given in startup project of MVC by .net framework with slight modification in that.

我已经创建了两个模型


  1. 登录

  2. 注册

创建两个控制器。


  1. 的LoginController

  2. RegisterController。

然后我就用他们两个在我的主页上显示(如Facebook只是一个例子)

Then i have use both of them to display in my home page (like facebook just an example)

示范code:
登录型号:

Model code: Login Model:

public class Login
{
    private string email;
    [Required]
    public string Email
    {
        get { return email; }
        set { email = value; }
    }
    private string password;
    [Required]
    public string Password
    {
        get { return password; }
        set { password = value; }
    }
}

注册型号

public class Register
{
    private string email;
    [Required]
    public string Email
    {
        get { return email; }
        set { email = value; }
    }
    private string password;
    [Required]
    public string Password
    {
        get { return password; }
        set { password = value; }
    }
    private string name;
    [Required]
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
}

登录观和寄存器都被创建使用创建选项。
这两个包含

View of Login and Register both is created using "Create" Option. Both contains

  <input type="submit" value="Create" />

现在,这两个意见是我的其他页面,主页。

Now, both views are on my other page, home page.

    @Html.Action("Index", "Login")
@Html.Action("Index", "Register")

这两个显示器还好,但是当我在任何的任何视图的创建按钮的点击,它也得到火在控制事件的另外一个。

Both display okay, but when i click on any of the "create" button of any of the view, it also gets fire the event in controller for the other one.

我的控制器code .... LoginController中。

My controller code....Logincontroller.

public ActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public ActionResult Index(Login lgobj)
    {
        System.Threading.Thread.Sleep(2000);
        string email = lgobj.Email;
        string password = lgobj.Password;
        return View();
    }

RegisterController:

RegisterController:

  [HttpGet]
    public ActionResult Index()
    {
        return View();


    }

    [HttpPost]
    public ActionResult Index(Register model)
    {
        return View();
    }

任何人都可以请注明原因,或者说是我的code失踪?

Can anyone please specify the reason, or what is missing in my code?

如果不清晰,请让我知道,我会形容了。

推荐答案

试着改变你的主页查看这样的:

Try changing your Home View to this:

@using (Html.BeginForm())
{
    @Html.Action("Index", "Login") 
}

@using (Html.BeginForm())
{
    @Html.Action("Index", "Register") 
}

我认为正在发生的事情是,你在提交调用 POST 到错误的控制器,因为有形式,没有明显差异。

What I think is happening is that your submit is calling a POST to the wrong controller, as there is no distinct difference of forms.

这篇关于问题与单一视图多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆