简体   繁体   中英

Getting exception for <%=@Html.DropDownList%> {“Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.”}

The Project is on .Net Framnework 3.5 and has MVC framework 1.0 The ViewModel is:

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;
    }
}

The controller is:

 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);

    }

}

The view is:

<%@ 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; <%=@Html.TextBox("pInstance",@Model.processInstance) %></td>
                        <td width ="50%"> <label for ="Mail Id">Mail Id: </label> &nbsp;&nbsp; <%=@Html.TextBox("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; <%=@Html.TextBox("sNo") %></td>
                    <td width ="50%"> <label for ="Name Insured">Name Insured: </label> &nbsp;&nbsp; <%=@Html.TextBox("nameInsured") %> </td>
                </tr>
                <tr>
                    <td width="50%"> <label for="Broker Code"> Broker Code: </label> &nbsp;&nbsp; <%=@Html.TextBox("brokerCode") %></td>
                    <td width ="50%"> <label for ="Broker Name">Broker Name: </label> &nbsp;&nbsp; <%=@Html.TextBox("brokerName") %> </td>
                </tr>
                 <tr>
                    <td width="50%"> <label for="Product Code"> Product Code: </label> &nbsp;&nbsp; <%=@Html.DropDownList("prodlist",@Model.products)%></td>
                    <td width ="50%"> <asp:Button ID="Button1" runat ="server"  Text ="Add Product" /> </td>
                </tr>
            </table>
         </td>
        </tr>
       </table>
    </div>

<% } %>
</div>

In the view I find HTMLhelper dropdownlist but at run time it gives an exception <%=@Html.DropDownList%> {"Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server."}

In MVC Framework 1.0 what is the best way to do a list item drop down box.

用纯HTML <button><input type="submit" />元素替换<asp:Button ID="Button1" runat="server" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM