开发者

submit View in ASP.NET MVC

How submit list View in ASP.NET MVC. List View dont have

input type="submit" value="Save"

and I dont know where to put it.

Problematic  code is:



  <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcZezanje.Models.student1>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Studenti
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Studenti</h2>

    <table class="data-table">
        <tr>

            <th>
                Br. Indexa
            </th>
            <th>
                Prezime
            </th>
            <th>
                Ime
            </th>            
        </tr>

    <% foreach (var item in Model) { %>
            <tr>         
            <td>
                <%= Html.Encode(item.id_stud) %>
            </td>
            <td>开发者_C百科;
                <%= Html.Encode(item.prezime) %>
            </td>
            <td>
                <%= Html.Encode(item.ime) %>
            </td>           
        </tr>   
    <% } %>
    </table>
    <p>
        <%= Html.ActionLink("Create New", "Create") %>
    </p>
</asp:Content>


What do you want to submit? This code displays list of students. There is no user input. If there is no user input, there is no need to place submit button. if you want to edit user data, you'll have to do something like:

<form method="post" action="/Students/Save">

<table class="data-table">
    <tr>

        <th>
            Br. Indexa
        </th>
        <th>
            Prezime
        </th>
        <th>
            Ime
        </th>            
    </tr>

<% int i = 0; foreach (var item in Model) { %>
        <tr>         
        <td>
            <%= Html.TextBox("students[" + i + "].id_stud", item.id_stud) %>
        </td>
        <td>
            <%= Html.TextBox("students[" + i + "].prezime", item.prezime) %>
        </td>
        <td>
            <%= Html.TextBox("students[" + i + "].ime", item.ime) %>
        </td>           
    </tr>   
<% i++;} %>
</table>


<input type="submit" />
</form>

Here you can read about binding to list:

http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

It has changed a little, you don't have to specify index anymore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜