当我在编辑器模板中为网格弹出创建设置元素的值时,将控制器发布为null

时间:2013-09-17 13:10:49

标签: asp.net-mvc kendo-ui kendo-grid

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

控制器功能

[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; }
}

1 个答案:

答案 0 :(得分: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();