0

asp.net mvc3 でグリッドを使用してデータをバインドしました。バインド テーブルの編集リンクに問題があります。編集リンクをクリックしても応答しません。ここに私が持っているものがあります:

Teacher.cs

public class Teacher
{
    public static List<Teacher> GetList { get; set; }

    public int  T_Id { get; set; }
    public string T_Name { get; set; }
    public string T_Address { get; set; }
    public string Sub_Id { get; set; }  


}

教師コントローラー

public ActionResult Edit(int id,string T_Name,string T_Address,string Sub_Id)
{
    // Teacher list= new Teacher();
    var edit = EditList();
    //list.T_Id = Convert.ToInt32(T_Id);
    return View(edit);   
}

[HttpPost]
public ActionResult EditList()
{

    var editlist = new List<Teacher>();
    using (SqlConnection conn = new SqlConnection(@"Integrated ecurity=SSPI;Persist Security Info=False;Initial Catalog=Demo;Data Source=CIPL41\SQLEXPRESS"))
    {

        conn.Open();
        var modeledit = new Teacher();
        SqlCommand cmd = new SqlCommand("edit", conn);
        cmd.CommandType = CommandType.StoredProcedure;               
        cmd.Parameters.AddWithValue("@T_Id", modeledit.T_Id);
        cmd.Parameters.AddWithValue("@T_Name", modeledit.T_Name);
        cmd.Parameters.AddWithValue("@T_Address", modeledit.T_Address);
        cmd.Parameters.AddWithValue("@Sub_Id", modeledit.Sub_Id);
        cmd.ExecuteNonQuery();
        conn.Close();enter code here

        editlist.Add(modeledit);
    }
    return View(editlist);
}
4

1 に答える 1

0

これは私のHtmlコードです:

インデックス.cshtml:

@model IEnumerable<MvcApplication1.Models.Teacher>

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>
<p>

    @Html.ActionLink("Create New", "Create")

</p>
<table>
<tr>
    <th></th>
    <th>
        T_Id
    </th>
    <th>
        T_Name
    </th>
    <th>
        T_Address
    </th>
    <th>
        Sub_Id
    </th>
</tr>


@foreach (var item in Model) {
<tr>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.T_Id}) |
        @Html.ActionLink("Details", "Details", new { id=item.T_Id }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.T_Id})
    </td>
    <td>
        @item.T_Id
    </td>
    <td>
        @item.T_Name
    </td>
    <td>
        @item.T_Address
    </td>
    <td>
        @item.Sub_Id
    </td>
</tr>

}

 **Edit.cshtml:**




@model MvcApplication1.Models.Teacher

@{
ViewBag.Title = "Edit";
}   

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript">     </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Teacher</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.T_Id)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.T_Id)
        @Html.ValidationMessageFor(model => model.T_Id)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.T_Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.T_Name)
        @Html.ValidationMessageFor(model => model.T_Name)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.T_Address)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.T_Address)
        @Html.ValidationMessageFor(model => model.T_Address)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Sub_Id)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Sub_Id)
        @Html.ValidationMessageFor(model => model.Sub_Id)
    </div>

    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>
}

<div>
@Html.ActionLink("Back to List", "Index")

于 2013-05-03T05:52:54.943 に答える