簡體   English   中英

為什么我在MVC中的按鈕不起作用?

[英]Why my button in MVC doesn't work?

我有以下代碼:

 @model IEnumerable<PamelaFundacionFinal.Models.Escuela>

 @{
     ViewBag.Title = "Index";
 }
  <h2>Escuelas registradas</h2>

  <p>
 <button name="Edit" class="btn btn-default"><b>
@Html.ActionLink("Create New", "Create")</b></button></p>
  <table class="table">
     <tr>
       <th>
          @Html.DisplayNameFor(model => model.Nombre)
        </th>
         <th>
            @Html.DisplayNameFor(model => model.Direccion)
          </th>
          <th>
            @Html.DisplayNameFor(model => model.Telefono)
          </th>
          <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Nombre)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Direccion)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Telefono)
            </td>
            <td>
   @Html.ActionLink("Edit", "Edit", new { id = item.Escuela_ID })
  <button name="Edit" class="btn btn-default">
    @Html.ActionLink("Details", "Details", new { id = item.Escuela_ID })</button>
 <button name="Edit" class="btn btn-default">
@Html.ActionLink("Delete", "Delete", new { id = item.Escuela_ID })</button>
    </td>
        </tr>
    }

    </table>

不用擔心,所有操作都參考了他們自己的控制器,我的問題是我有兩種情況:

  1. 我正在@Html.ActionLink("Edit", "Edit", new { id = item.Escuela_ID })對另一個控制器的引用,因此我可以創建一個新控制器,但這是簡單的文本
  2. 然后,我嘗試將該引用放入按鈕中,這樣看起來很不錯: <button name="Edit" class="btn btn-default">@Html.ActionLink("Delete", "Delete", new { id = item.Escuela_ID })</button>但是它不起作用。

我知道我的書寫方式不正確,但是我需要幫助,因為我是該語言的新手,我並不十分了解語法。 我正在使用Visual Studio 2013和SQL Server運行數據庫(與數據庫的連接運行良好,這不是數據庫的問題)。

您可以設置由HTML幫助程序生成的<a>標簽的樣式。

 @Html.ActionLink("Edit", "Edit", new { id = item.Escuela_ID },
                   new { @class = "btn btn-default" })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM