将数据从视图传递到ASP.NET MVC中的控制器

将数据从视图传递到ASP.NET MVC中的控制器

问题描述:

你好朋友

我是asp.net MVC应用程序的新手,所以请帮助我..

我创建了一个模型,视图,控制器
创建和显示是两个视图

这是我的查看代码

Hi friends

i am new to asp.net MVC application.so please help me..

I created one model,view ,controller
Create and show are the two views

this is my view code

<form method="post" action="Create" runat="server">
    <div>
        <%if (Model != null)
          { %>
        <%=Model.Id%>
        <%=Model.Name%>
        <%=Model.Dateofbirth%>
        <%=Model.Designation%>
        <%=Model.Salary%>
        <%} %>
    </div>
    <%=Html.TextBoxFor(m=>m.Id )%><br />
    <%=Html.TextBoxFor(m=>m.Name) %><br />
    <%=Html.TextBoxFor(m=>m.Dateofbirth) %><br />
    <%=Html.TextBoxFor(m=>m.Designation )%><br />
    <%=Html.TextBoxFor(m=>m.Salary )%><br />
    <input type="button" value="Create"  />
    </form>



我在控制器中写了两种方法

就像



i wrote two methods in controller

like

[HttpGet]
       public ActionResult Create()
       {
           return View();
       }

       [AcceptVerbs(HttpVerbs.Post)]
       public ActionResult Create(Employee emp)
       {
           return View("Show", emp);
       }



在回发中,我想将用户输入的数据转移到另一个视图,即我的示例中的显示"

你们能建议我吗?


在这里,发回动作不会起作用.每次在发回中击中相同的get方法时,也会发生



in post back i want to transfer the data entered by the user to another view i.e "show" in my example

can u guys plz suggest me


here post back action is not hitting .every time the same get method is hitting in post back also

尝试将按钮更改为SUBMIT.

替换

Try changing the BUTTON to SUBMIT.

Replace

<input type="button" value="Create" onclick="" />




with

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