2014-06-18 44 views
0

該項目位於.Net Framnework 3.5和具有MVC框架1.0 視圖模型是:獲取<%= @ Html.DropDownList%>的異常t {「類型'Button'的控件'Button1'必須放置在runat = server的表單標籤中。」}

namespace MockBDPWorkflowTestApp.ViewModels 


{ 
    public class WorkFlowTestViewModel 
    { 
    public string processInstance { get; set; } 
    public string mail { get; set; } 
    public String[,] productCode = { { "GL", "0" }, { "PROP", "1" }, 
         { "Auto", "2" }, { "Other", "3"}, 
         { "Multi", "4" } }; 

    public List<SelectListItem> products; 
    } 
} 

控制器是:

public class WorkFlowTestController : Controller 
{ 
    // 
    // GET: /WorkFlowTest/ 

    public ActionResult OpenSubmission(string processId, string mailId) 
    { 
     var SubmissionModelView = new MockBDPWorkflowTestApp.ViewModels.WorkFlowTestViewModel{processInstance =processId, mail =mailId} ; 
     SubmissionModelView.products = new List<SelectListItem>(); 
     SubmissionModelView.products.Add(new SelectListItem { Text = "GL", Value = "0", Selected = true }); 
     SubmissionModelView.products.Add(new SelectListItem { Text = "Property", Value = "1" }); 
     SubmissionModelView.products.Add(new SelectListItem { Text = "Package", Value = "2" }); 
     SubmissionModelView.products.Add(new SelectListItem { Text = "Island Marine", Value = "3" }); 
     return View("Submission", SubmissionModelView); 

    } 

} 

的觀點是:

<%@ Page Language="C#"  Inherits="System.Web.Mvc.ViewPage<MockBDPWorkflowTestApp.ViewModels.WorkFlowTestViewModel>" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 

<head id="Head1" runat="server"> 

<title>Submission</title> 

</head> 

<body> 

    <div> 

    <% using (Html.BeginForm()) 
     { 
     %> 
     <div> 
      <table > 
      <tr> 
       <td> 
       <div id="SID"> 
        <table id="tblID" cellpadding ="0" cellspacing ="0" border="1"> 
        <tr> 
         <td width ="50%"> <label for="Process Inastance Id"> Process Inastance Id: </label> &nbsp;&nbsp; <%[email protected]("pInstance",@Model.processInstance) %></td> 
         <td width ="50%"> <label for ="Mail Id">Mail Id: </label> &nbsp;&nbsp; <%[email protected]("mail",@Model.mail) %> </td> 
        </tr> 
       </table> 
      </div> 
      <br /><br /> 
      <table id="tblDet" cellpadding ="0" cellspacing ="0" > 
       <tr> 
        <td width="50%"> <label for="Submission Number"> Submission Number: </label> &nbsp;&nbsp; <%[email protected]("sNo") %></td> 
        <td width ="50%"> <label for ="Name Insured">Name Insured: </label> &nbsp;&nbsp; <%[email protected]("nameInsured") %> </td> 
       </tr> 
       <tr> 
        <td width="50%"> <label for="Broker Code"> Broker Code: </label> &nbsp;&nbsp; <%[email protected]("brokerCode") %></td> 
        <td width ="50%"> <label for ="Broker Name">Broker Name: </label> &nbsp;&nbsp; <%[email protected]("brokerName") %> </td> 
       </tr> 
       <tr> 
        <td width="50%"> <label for="Product Code"> Product Code: </label> &nbsp;&nbsp; <%[email protected]("prodlist",@Model.products)%></td> 
        <td width ="50%"> <asp:Button ID="Button1" runat ="server" Text ="Add Product" /> </td> 
       </tr> 
      </table> 
     </td> 
     </tr> 
     </table> 
    </div> 

<% } %> 
</div> 

在我找到視圖的HtmlHelper下拉列表,但在運行時它提供了一個例外<%= @ Html.DropDownList%> {「控制‘Button1的’類型的‘按鈕’的必須放在一個表格標籤與內runat = server。「}

在MVC Framework 1.0中,做一個列表項下拉框的最佳方法是什麼?

+0

您在混合兩種不同的Microsoft技術。 'asp:Button />'是webforms,並且在ASP.NET MVC視圖中不能正確運行。 –

+0

你在混合asp.net mvc和asp.net標記。這不被支持,至少不應該發生。對於按鈕,您應該只有'「 – Andrei

回答

0

用純HTML <button><input type="submit" />元素替換您的<asp:Button ID="Button1" runat="server" />

相關問題