2012-08-08 55 views
0

我想構建一個簡單的ASP.net MVC應用程序。無法從視圖調用另一個動作

我的控制器如下所示。

namespace CustomerReadAndLoad.Controllers 
{ 
    public class CustomerController : Controller 
    { 
     // 
     // GET: /Customer/ 
     public ActionResult Index() 
     { 
      return View(); 
     } 

     public ActionResult LoadCustomer() 
     { 
      return View(); 
     } 

     [HttpPost] 
     public ActionResult DisplayCustomer() 
     { 
      Customer obj = new Customer(); 
      obj.ID = Convert.ToInt16(Request.Form["CuatomerID"]); 
      obj.Name = Convert.ToString(Request.Form["CuatomerName"]); 
      obj.Amount = Convert.ToInt16(Request.Form["CuatomerAmount"]); 
      return View(obj); 
     } 
    } 
} 

我想包括在LoadCustomerView行動DisplayCustomer像下面

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>  
<!DOCTYPE html>  
<html> 
    <head runat="server"> 
    <meta name="viewport" content="width=device-width" /> 
    <title>LoadCustomer</title> 
    </head> 

    <body> 
    <div> 
    <form action ="DisplayCustomer" method ="post"> 
     Welcome to Customer management System<br /> 
     Enter the below details <br /> 
     Customer ID :- <input type="text" name = "CuatomerID" /><br /> 
     Customer Name :- <input type="text" name = "CuatomerName" /><br /> 
     Customer Amount :- <input type="text" name = "CuatomerAmount" /><br /> 
     <input type ="button" value="ClickHere" /> 
    </form> 
</div> 

我不能在視DisplayCustomer一旦我點擊提交按鈕。

+1

改變輸入的類型sumbmit和形式的行動,以「/客戶/ DisplayCustomer」 – Hadas 2012-08-08 09:55:40

+0

Tanq :-)我知道了。 – user1584313 2012-08-08 11:10:38

+0

您可能也想看看HTML助手。如果你現在學習它們,而不是當你的應用程序開始對你哭泣時,它們將爲你節省很多麻煩。 (例如@using(Html.BeginForm()){},@ Html.EditorFor())只是一個頭。這不是100%的要求,但你會回來這麼多,人們會告訴你,如果你不開始使用他們:)(PS我寫了Razor格式的例子,因爲它是我唯一的格式使用和我很舒服) – Pluc 2012-08-08 11:18:35

回答

0

試試這個:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>  
<!DOCTYPE html>  
<html> 
    <head runat="server"> 
    <meta name="viewport" content="width=device-width" /> 
    <title>LoadCustomer</title> 
    </head> 

    <body> 
    <div> 
    <%using(Html.BeginForm("DisplayCustomer", "Customer", FormMethod.Post)){%> 
     Welcome to Customer management System<br /> 
     Enter the below details <br /> 
     Customer ID :- <input type="text" name = "CuatomerID" /><br /> 
     Customer Name :- <input type="text" name = "CuatomerName" /><br /> 
     Customer Amount :- <input type="text" name = "CuatomerAmount" /><br /> 
     <button type ="submit">"ClickHere"</button>   
    <%}%> 
</div> 
相關問題