0

在我看来有两个网格。当我在第一个网格中选择一行时,第二个是根据第一个绑定的。我想要做的是从第一个中获取公共参数,在第二个中使用在只读或禁用输入中创建模板。我的问题是输入元素从第一个网格获取参数,但不要发布到控制器。

控制器功能

[AcceptVerbs(HttpVerbs.Post)]
public JsonResult DonemKursSinifiOlustur([DataSourceRequest] DataSourceRequest request, DonemKursSinifi model,string DonemId, string DersId, string EgitmenId )
{

    if (model != null && ModelState.IsValid)
    {
        Helper.Islemci.DonemKursSinifiTanimla(model);
    }
    return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}

model.DonemId、model.DersId、model.EgitmenId 和 DonemId、DersId、EgitmenId 为空。

用于网格创建和更新的 EditorTemplate 视图

@model Kurslar.Models.DonemKursSinifi
@using (Html.BeginForm("DonemKursSinifiOlustur","Tanim",FormMethod.Post))
{
<table>
        <tr>
            <td>
                Lütfen Gün ve Saati Belirtiniz:
            </td>
            <td>
                @Html.Kendo().AutoCompleteFor(m=>m.Tanim)
            </td>
        </tr>
        <tr>
            <td>
                Donem :
            </td>
            <td>

                @Html.Kendo().AutoCompleteFor(m=>m.DonemBaslangicBitis)
                @Html.HiddenFor(m => m.DonemId)
            </td>
        </tr>
        <tr>
            <td>
                Ders Adı:
            </td>
            <td>

                @Html.Kendo().AutoCompleteFor(m=>m.DersAdi)
                @Html.HiddenFor(m => m.DersId)
              </td>
        </tr>
        <tr>
            <td>
                Eğitmen
            </td>
            <td>
                @Html.Kendo().AutoCompleteFor(m=>m.EgitmenAdiSoyadi)
                @Html.HiddenFor(m => m.DonemId)

            </td>
        </tr>
    </table>}

第一个 AutoCompleteFor 可以正常工作,因为从用户那里获取输入,而不是在设置之前。

*和我的 javaScript 代码将参数填充到 EditorTemplate * 并且工作正常

    var grid = $("#donemGrid").data("kendoGrid");
    var rows = grid.select();
    alert(rows);
    try {
        var donemID = grid.dataItem(rows).DonemId;
        var dersID = grid.dataItem(rows).DersId;
        var egitmenID = grid.dataItem(rows).EgitmenId;
        var dersAdi = grid.dataItem(rows).DersAdi;
        var egitmenAdiSoyadi= grid.dataItem(rows).EgitmenAdiSoyadi;
        var donemBaslangicBitis = grid.dataItem(rows).DonemBaslangicBitis;
    } catch (e) {
        alert(e);
    }

    $("#DonemBaslangicBitis").data("kendoAutoComplete").value(donemBaslangicBitis);
    $("#DersAdi").data("kendoAutoComplete").value(dersAdi);
    $("#EgitmenAdiSoyadi").data("kendoAutoComplete").value(egitmenAdiSoyadi);
    $("#DonemId").val(donemID);
    $("#DersId").val(dersID);
    $("#EgitmenId").val(egitmenID);

*如果需要,我的模型 *

public class DonemKursSinifi
{
    [Key]
    [Required]
    [PersistentProperty(IsAutoIncremented = true)]
    public int Id { get; set; }

    [PersistentProperty]
    public string Tanim { get; set; }

    [PersistentProperty]
    public int DonemId { get; set; }

    [PersistentProperty]
    public int DersId { get; set; }

    [PersistentProperty]
    public int EgitmenId { get; set; }

    [PersistentProperty]
    public int KontenjanSayisi { get; set; }

    [PersistentProperty]
    public int TarifeId { get; set; }

    [PersistentProperty]
    public int IslemNo { get; set; }  // default 1

    public string EgitmenAdiSoyadi { get; set; }

    public string DersAdi { get; set; }

    public string DonemBaslangicBitis { get; set; }
}
4

1 回答 1

0

好的,可能您在网格中重复了 id 并且在相同的表单中也具有相同的名称属性来执行此操作:

@Html.HiddenFor(m => m.DersId)

也许你可以这样做:

形式:

@model Kurslar.Models.DonemKursSinifi
@using (Html.BeginForm("DonemKursSinifiOlustur","Tanim", FormMethod.Post, new { id="myform"}))
{
  <input type="hidden" value="" name="Tanim" />
  <input type="hidden" value="" name="DonemBaslangicBitis" />
  <input type="hidden" value="" name="DonemId" />
  <input type="hidden" value="" name="DersAdi" />
  <input type="hidden" value="" name="DersId" />
  <input type="hidden" value="" name="EgitmenAdiSoyadi" />
  <input type="hidden" value="" name="DonemId" />
}

桌子:

<table>
    <tr>
        <td>Lütfen Gün ve Saati Belirtiniz:</td>
        <td>@Html.Kendo().AutoCompleteFor(m=>m.Tanim)</td>
    </tr>
    <tr>
        <td>Donem :</td>
        <td>@Html.Kendo().AutoCompleteFor(m=>m.DonemBaslangicBitis) @Html.HiddenFor(m => m.DonemId)</td>
    </tr>
    <tr>
        <td>Ders Adı:</td>
        <td>@Html.Kendo().AutoCompleteFor(m=>m.DersAdi) @Html.HiddenFor(m => m.DersId)</td>
    </tr>
    <tr>
        <td>Eğitmen</td>
        <td>@Html.Kendo().AutoCompleteFor(m=>m.EgitmenAdiSoyadi) @Html.HiddenFor(m => m.DonemId)</td>
    </tr>
</table>

js:

var 
    grid = $("#donemGrid").data("kendoGrid"),
    rows = grid.select(),
    form = $('#myform');

form.find('input[name="DonemBaslangicBitis"]').val(grid.dataItem(rows).DonemBaslangicBitis);
form.find('input[name="DersAdi"]').val(grid.dataItem(rows).DersAdi);
form.find('input[name="EgitmenAdiSoyadi"]').val(grid.dataItem(rows).EgitmenAdiSoyadi);
form.find('input[name="DonemId"]').val(grid.dataItem(rows).DonemId);
form.find('input[name="DersId"]').val(grid.dataItem(rows).DersId);
form.find('input[name="EgitmenId"]').val(grid.dataItem(rows).EgitmenId);

form.submit();
于 2013-09-17T13:48:33.773 回答