2013-04-24 45 views
2

我在ASP.NET MVC3工作,並創建一個表單顯示System.Web.Mvc.Html.MvcForm {}之間的表單字段:而與@ Html.BeginForm(名稱MVC3形式),它在資源管理器

@Html.BeginForm(null, null, FormMethod.Post, new { name = "frmAcnt", id = "frmAcnt" }) 

因爲我不想給動作和控制器名稱。它工作正常,但在Firefox或任何其他瀏覽器,它顯示在這兩行之間的形式。我能做些什麼來將其從顯示中刪除?

System.Web.Mvc.Html.MvcForm { 

} 

,並在頁面的源代碼此行是顯示

<form action="/Home/AccCode" id="frmAcnt" method="post"  name="frmAcnt">System.Web.Mvc.Html.MvcForm 
下面

是我的看法

@model CBS.Models.AccntBD 

@{ 
ViewBag.Title = "AccCode"; 
Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<h2>AccCode</h2> 

<div> 
@Html.BeginForm(null, null, FormMethod.Post, new { name = "frmAcnt", id = "frmAcnt" }) 
{ 

<table class="tablestyle"> 
<tr> 
<td> 
<input type="text" id="AcCode" name="AcCode" maxlength="10" placeholder="Account Code" autofocus="true" class="required" /> 

</td> 
</tr> 

<tr> 
<td> 
<label>Description</label> 
</td> 
<td> 
    <input type="text" id ="Descrip" name="Descrip" maxlength="150" placeholder="Desription..." class="Descrip"/> 
        </td> 
</tr> 

    <tr> 
    <td> 
    <span> 

    <input type="button" name="clear" value="Cancel" onclick="clearForm(this.form);" > 
    </span> 

      <span> 
        <input type="submit" id="sve" name="action" value="Save" /> 
     </span> 
     <span> 
     <input type="button" id="edi" value="Edit" name="action"/> 
        </span> 
    <span> 
    <input type="button" value="Delete" id="del" name="action"/>  
</span> 
</td> 
<td>          
</td>  
</tr> 
<tr>  
<td> 
</td> 
</tr> 
</table>  
} 
</div> 
+0

請發表您該頁面視圖。 – 2013-04-24 07:45:16

回答

2

一次嘗試這種理想情況下,你可以使用@using (Html.BeginForm()){ }定義形式

查看

@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "frmAcnt", id = "frmAcnt" })) 
{ 
    @* Your Form Content Here *@ 
} 

HTML輸出是

<form name="frmAcnt" method="post" id="frmAcnt" action="/"></form> 
+0

謝謝satpal它適用於我 – 2013-04-24 08:12:51

+0

發生這種情況是因爲您使用'Html.BeginForm'作爲獨立表達式。它返回一個對象,並將其輸出到頁面中,該頁面調用'obj.ToString()',默認返回類名稱。當你使用'using'(你應該),創建的表單對象永遠不會被轉換爲字符串。所以你得到的唯一輸出是由窗體的構造函數和析構函數生成的直接響應寫入。 – GSerg 2013-04-24 08:23:33

+0

@churahi,如果它的工作和足夠好接受它作爲回答 – Satpal 2013-04-24 08:24:02