Kendo UI Grid with Foreign Key Column Displaying Blank After Creation - asp.net-mvc

Hi I have a grid with a kendo foreign key column and editing in popup mode. When I insert a new record and pulse sort or filter the foreign key columan shows blank until I press f5 on the browser
GRID
#(Html.Kendo().Grid(Model) // Bind the grid to the Model property of the view
.Name("Usuarios")
.AutoBind(true)
.Columns(columns =>
{
columns.Bound(p => p.Id).Visible(false);
columns.Bound(p => p.Nombre).Width(300);
columns.Bound(p => p.Apellido1).Width(300);
columns.Bound(p => p.Apellido2).Width(300);
columns.Bound(p => p.Codusuario).Width(300);
columns.Bound(p => p.Fechacambiopassword).Width(300);
columns.Bound(p => p.Idperfil).Width(300);
columns.ForeignKey(p => p.Idperfil, (System.Collections.IEnumerable)ViewBag.Perfiles, "Id", "Descripcion").Width(300).EditorTemplateName("PerfilesDropDownList");
columns.Command(command => { command.Edit(); command.Custom("Eliminar").Click("grid_remove"); }).Width(200);
})
.ToolBar(commands => commands.Create())
.Sortable(s => s.SortMode(GridSortMode.SingleColumn))
.Filterable()
.Pageable()
.Scrollable(scroll => scroll.Height("auto"))
.Editable(editable => editable.Mode(GridEditMode.PopUp).DisplayDeleteConfirmation(false).TemplateName("UsuariosEdicion").Window(w => w.Title("Editar Usuario").Width(700)))
.DataSource(dataSource => dataSource
.Ajax()
.Sort(sort => sort.Add("Apellido1").Ascending())
.Model(model => model.Id(p => p.Id))
.Create(create => create.Action("InsertarUsuario", "Account"))
.Read(read => read.Action("ObtenerUsuarios", "Account").Data("getAdditionalData"))
.Update(update => update.Action("ModificarUsuario", "Account"))
.Destroy(destroy => destroy.Action("EliminarPerfil", "Account"))
.Events(e => e.RequestStart("grid_mostrarspinner").RequestEnd("grid_ocultarspinner").Error("error"))
.PageSize(5)
)
.Events(e => e.Remove("grid_remove").Edit("editar"))
)
Controller
public async Task<JsonResult> InsertarUsuario([DataSourceRequest] DataSourceRequest request, Usuarios usuario)
{
if (ModelState.IsValid)
{
Error error = await ServicioSeguridad.Current.InsertarUsuarioAsync(usuario);
}
return Json(new[] { usuario }.ToDataSourceResult(request, this.ModelState));
}
Editor Template
#using Ibermatica.Info33Plus.Modelos;
#model Usuarios
<div style="width:700px;">
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Nombre)
</div>
<div class="editor-field col-md-6">
#Html.TextBoxFor(u => u.Nombre, new { #class = "k-input k-textbox wide-full" })
</div>
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Apellido1)
</div>
<div class="editor-field col-md-6">
#Html.TextBoxFor(u => u.Apellido1, new { #class = "k-input k-textbox wide-full" })
</div>
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Apellido2)
</div>
<div class="editor-field col-md-6">
#Html.TextBoxFor(u => u.Apellido2, new { #class = "k-input k-textbox wide-full" })
</div>
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Codusuario)
</div>
<div class="editor-field col-md-6">
#Html.TextBoxFor(u => u.Codusuario, new { #class = "k-input k-textbox wide-full" })
</div>
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Password)
</div>
<div class="editor-field col-md-6">
#Html.PasswordFor(u => u.Password, new { #class = "k-input k-textbox wide-full" })
</div>
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Perfiles.Descripcion)
</div>
<div class="editor-field col-md-6">
#(Html.Kendo().DropDownList()
.HtmlAttributes(new { #class = "wide-full" })
.Name("Perfiles")
.DataValueField("Id")
.DataTextField("Descripcion")
.BindTo((System.Collections.IEnumerable)ViewBag.Perfiles)
.OptionLabel("Selecciona un perfil...")
)
</div>
<div class="editor-label col-md-4">
#Html.LabelFor(u => u.Email)
</div>
<div class="editor-field col-md-4">
#Html.TextBoxFor(u => u.Email, new { #class = "k-input k-textbox wide-full" })
#Html.ValidationMessageFor(u => u.Email)
</div>
</div>

you should read your data when a process occured.
.DataSource(ds => ds
.Events(events => events.Sync("sync_handler"))
)
function sync_handler(e) {
this.read();
}

Related

Kendo Parsing Date

I have custom popup window and it works. Also I am retrieving data from database correctly and binding data. While editing these records from popup whenever date or month is over 12 , there is an error on localhost and says that for example" 12/08/'2011 is not a valid date.
Here is my codes, please help me..
#model xxxx.Il
<h3>Customized Il</h3>
<br />
#Html.HiddenFor(model => model.Id)
#Html.HiddenFor(model => model.CustId)
#Html.HiddenFor(model => model.DegistirenKullanici)
#Html.HiddenFor(model => model.DegistirmeTarihi)
#Html.HiddenFor(model => model.KayitKullanici)
<div>
#Html.LabelFor(model => model.IlAdi)
#Html.EditorFor(model => model.IlAdi)
#Html.ValidationMessageFor(model => model.IlAdi)
</div>
<div>
#Html.LabelFor(model => model.KayitTarihi)
#Html.Kendo().DatePickerFor(model => model.KayitTarihi).Format("dd/mm/yyyy")
#Html.ValidationMessageFor(model => model.KayitTarihi)
</div>
<script>
kendo.culture("en-GB");
</script>
And here is my view cshtml codes;
#using Kendo.Mvc.UI;
#model xxxxx.Il
<section id="gallery">
<h2 class="ra-well-title">Iller</h2>
<div>
<input id='txtIlId' value="" style="width:100%; text-align:center;" class="k-textbox" placeholder="Id'ye göre Arama'" />
<br>
<br />
<input id='txtIlAdi' value="" style="width:100%; text-align:center;" class="k-textbox" placeholder="Ada göre Arama'" />
<br>
<br />
</div>
<script>
kendo.culture("en-GB");
</script>
#(Html.Kendo().Grid<xxxx.Il>().Name("Iller")
.Columns(columns =>
{
columns.Bound(p => p.Id);
columns.Bound(p => p.IlAdi);
columns.Bound(p => p.DegistirenKullanici);
columns.Bound(p => p.DegistirmeTarihi);
columns.Bound(p => p.KayitKullanici);
columns.Bound(p => p.KayitTarihi).Format("{0:dd/mm/yyyy}");
columns.Command(command => { command.Edit(); }).Width(250);
})
.Pageable(pageable => pageable.Refresh(true))
.Sortable()
.AutoBind(true)
.Selectable()
.Navigatable()
.Filterable()
.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("IlModel").Window(w => w.Width(450)).Window(w => w.Title("Düzenle")))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.Read(read => read.Action("Il_Read", "Tanimlar").Data("getAdditionalData"))
.Update(update => update.Action("Il_Guncelle", "Tanimlar"))
)
)
</section>
<script type="text/javascript">
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
function onClickBul(e) {
//kendoConsole.log("event :: click (" + $(e.event.target).closest(".k-button").attr("id") + ")");
$('#Iller').data('kendoGrid').dataSource.read();
}
$('#txtIlAdi').keyup(function () {
$('#Iller').data('kendoGrid').dataSource.read();
});
function getAdditionalData(e) {
return {
//iMrpId: 2
Iladi: $('#txtIlAdi').val()
};
}
</script>
This is the way how I get a kendo calendar date.
var selectedDate = kendo.toString(kendo.parseDate($("#diningCalendar").data("kendoCalendar").current()), 'MM/dd/yyyy')
use kendo.toString(kendo.parseDate())
Hope this helps.

How to get selected row value in the KendoUI without javascript

I have the following kendoUI grid:
<div class="row">
<div class="col-md-12">
<h4>List of SSF Pension Subscription</h4>
<p>
#(Html.Kendo().Grid(Model)
.Name("Grid")
.HtmlAttributes(new { style = "border: 0;" })
.Columns(columns =>
{
columns.Bound(s => s.PensionNumber);
columns.Bound(s => s.FirstName);
columns.Bound(s => s.FatherName);
columns.Bound(s => s.GrandName);
columns.Bound(s => s.FamilyName);
columns.Bound(s => s.BankLookup.BankName);
})
.Sortable()
.Navigatable()
.Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
.DataSource(dataSource => dataSource.Server()
.Model(model => model.Id(s => s.MemberID)))
)
</p>
#Html.ActionLink("Edit", "Edit", null, new { id = ???????}, new { #class = "btn btn-default" })
</div>
I want to get the selected row id after clicking on the edit button and pass that id to the action method.
Thanks in advance

Kendo grid invokes read method on empty grid when column is clicked in ASP.NET MVC

I have a grid which loads data after search button is clicked. However i am running into the issue where when the user clicks on any of the column, it tends to call datasource read function.
Is there anyway to stop invoking read method when the column is clicked and only call the read function when search button is clicked?
Razor:
<div class="col-sm-6">
<div class="form-group">
#Html.LabelFor(model => model.EmployeeName, new { #class = "col-sm-4 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(model => model.EmployeeName, new { #class = "form-control"})
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="col-sm-6">
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<input id="btnSearch" type="submit" value="Search" class="btn" />
</div>
</div>
</div>
#(Html.Kendo().Grid<Portal.EmployeeViewModel>()
.Name("GridEmployeeInvitation")
.Columns(columns =>
{
columns.Bound(e => e.EmployeeNumber).Width("160px");
columns.Bound(e => e.EmployeeName).Width("180px");
})
.Excel(excel => excel
.FileName("File.xlsx")
.ProxyURL(Url.Action("Excel_Export_Save", "Shared"))
.AllPages(true)
)
.Pageable(x => x.PageSizes(new object[] { 10, 20, 50, 100, "All" }))
.Reorderable(reorder => reorder.Columns(true))
.AutoBind(false)
.Selectable()
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn))
.Scrollable(scr => scr.Height(322))
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.StartsWith("Starts with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to"))))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.ServerOperation(false)
.Read(read => read.Action("GetEmployees", "Admin").Data("GetSearchParameters"))
)
)
<script type="text/javascript">
$('#btnSearch').click(function (e) {
('#GridEmployeeInvitation').data('kendoGrid').dataSource.read();
});
function GetSearchParameters() {
return { employeeName: $("#EmployeeName").val()
};
}
</script>

Html.ActionLink doesn't call at all

I am having some problems solving this. The thing is, this is the only place it doesn't work, everywhere else in my project it works just fine and it's all the same.
here is my link:
<td class="col-sm-1 col-lg-1">#Html.ActionLink("Edit", "EditGrowWeek", "FinishedProductionMaintanance", new { #id = Model.growWeek.GWID }, new { #data_toggle = "modal", #data_target = "#editGrowWeek" })</td>
my controller:
[HttpGet]
public ActionResult EditGrowWeek(int id)
{
viewModel.growWeek = _ProductionGrowWeekRepository.GetOne(id);
return PartialView(viewModel);
}
[HttpPost]
//[ValidateAntiForgeryToken]
public ActionResult EditGrowWeek([Bind(Prefix="growWeek")] ProductionGrowWeek growWeek)
{
var growWeeks = _ProductionGrowWeekRepository.GetAll(growWeek.GProfileNo);
foreach (var week in growWeeks)
{
if (ModelState.IsValid)
{
_ProductionGrowWeekRepository.Edit(week);
}
}
return RedirectToAction("IndexGrowProfiles");
}
and finally my view:
#model SISCOM.ViewModel.FinishedProductionMaintananceViewModel
#{
Layout = null;
}
<div class="modal fade in" id="editGrowWeek" tabindex="-1" role="dialog" aria-labelledby="MyModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dissmiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
#using (Html.BeginForm("EditGrowWeek", "FinishedProductionMaintanance", FormMethod.Post))
{
#*#Html.AntiForgeryToken()*#
<form id="form">
#Html.ValidationSummary(true)
#Html.HiddenFor(model => model.growWeek.GWID)
#Html.HiddenFor(model => model.growWeek.CutSupplierCode)
#Html.HiddenFor(model => model.growWeek.DelvyWk)
#Html.HiddenFor(model => model.growWeek.Description_ID_)
#Html.HiddenFor(model => model.growWeek.Description_Product_)
#Html.HiddenFor(model => model.growWeek.Despatch)
#Html.HiddenFor(model => model.growWeek.FinishedDuration)
#Html.HiddenFor(model => model.growWeek.FinishedSite)
#Html.HiddenFor(model => model.growWeek.GapUpHandSite)
#Html.HiddenFor(model => model.growWeek.GapUpMCSite)
#Html.HiddenFor(model => model.growWeek.GerminationDuration)
#Html.HiddenFor(model => model.growWeek.GerminationSite)
#Html.HiddenFor(model => model.growWeek.Germinator)
#Html.HiddenFor(model => model.growWeek.GerminatorDuration)
#Html.HiddenFor(model => model.growWeek.GerminatorSite)
#Html.HiddenFor(model => model.growWeek.GProfileNo)
#Html.HiddenFor(model => model.growWeek.GrowWks1)
#Html.HiddenFor(model => model.growWeek.GrowWks2)
#Html.HiddenFor(model => model.growWeek.GrowWks3)
#Html.HiddenFor(model => model.growWeek.GrowWks4)
#Html.HiddenFor(model => model.growWeek.GrowWks5)
#Html.HiddenFor(model => model.growWeek.OrderWK)
#Html.HiddenFor(model => model.growWeek.PreGapDuration)
#Html.HiddenFor(model => model.growWeek.PreGapSite)
#Html.HiddenFor(model => model.growWeek.PrickOut)
#Html.HiddenFor(model => model.growWeek.PrickOutSite)
#Html.HiddenFor(model => model.growWeek.Priority)
#Html.HiddenFor(model => model.growWeek.ProdGrp)
#Html.HiddenFor(model => model.growWeek.ProdSeries)
#Html.HiddenFor(model => model.growWeek.ProdSeriesDetail)
#Html.HiddenFor(model => model.growWeek.ProductionGrowProfile)
#Html.HiddenFor(model => model.growWeek.RangeUpdateFlag)
#Html.HiddenFor(model => model.growWeek.Rooting_GermAssess)
#Html.HiddenFor(model => model.growWeek.SiteGrown)
#Html.HiddenFor(model => model.growWeek.SiteRange)
#Html.HiddenFor(model => model.growWeek.SiteSown)
#Html.HiddenFor(model => model.growWeek.Topping)
#Html.HiddenFor(model => model.growWeek.ToppingCode)
#Html.HiddenFor(model => model.growWeek.Transplant)
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.WksToDesp, "Weeks to despatch")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.WksToDesp, null, new { #class = "form-control", #placeholder = "Weeks to despatch" })
#Html.ValidationMessageFor(p => p.growWeek.WksToDesp, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.GapUp, "Gap up")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.GapUp, null, new { #class = "form-control", #placeholder = "Gap up" })
#Html.ValidationMessageFor(p => p.growWeek.GapUp, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Pinch1, "Pinch1")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Pinch1, null, new { #class = "form-control", #placeholder = "Pinch1" })
#Html.ValidationMessageFor(p => p.growWeek.Pinch1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Pinch2, "Pinch2")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Pinch2, null, new { #class = "form-control", #placeholder = "Pinch2" })
#Html.ValidationMessageFor(p => p.growWeek.Pinch2, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Space1, "Space1")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Space1, null, new { #class = "form-control", #placeholder = "Space1" })
#Html.ValidationMessageFor(p => p.growWeek.Space1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Space2, "Space2")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Space2, null, new { #class = "form-control", #placeholder = "Space2" })
#Html.ValidationMessageFor(p => p.growWeek.Space2, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Space3, "Space3")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Space3, null, new { #class = "form-control", #placeholder = "Space3" })
#Html.ValidationMessageFor(p => p.growWeek.Space3, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Check1, "Check1")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Check1, null, new { #class = "form-control", #placeholder = "Check1" })
#Html.ValidationMessageFor(p => p.growWeek.Check1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Edit" class="btn btn-default" />
</div>
</div>
</form>
}
</div>
</div>
</div>
</div>
I've been checking everywhere and this one doesn't make a call at all... any ideeas?
P.S. ... this might be connected so, on this page, (On the index that renders this partial) my footer is being rendered somewhere in the middle of my page in code..
This doesn't make a lot of sense but here it is. The problem was that everytime i generated values for that table it removed the partial view following it for some reason (if anyone can make sense of this behaviour and can explain please do.)
so, my index for this page used to look like this:
<div class="tab-content col-md-9 col-lg-9 growProfilePage">
<div class="col-md-12 col-lg-12">
<div class="col-md-4">
#{ Html.RenderPartial("ListGrowProfiles");}
</div>
<div class="col-md-8">
#{ Html.RenderPartial("ListGrowWeeks");}
#{ Html.RenderPartial("EditGrowWeek");}
</div>
</div>
</div>
now it looks like this:
<div class="tab-content col-md-9 col-lg-9 growProfilePage">
<div class="col-md-12 col-lg-12">
#{ Html.RenderPartial("EditGrowWeek");}
<div class="col-md-4">
#{ Html.RenderPartial("ListGrowProfiles");}
</div>
<div class="col-md-8">
#{ Html.RenderPartial("ListGrowWeeks");}
</div>
</div>
</div>
and it all works (curiously enough, on other pages it's still like before, the edit following the list and it works like that).

How redirected user with method POST?

How to redirect a user from the action with POST request?
I have:
public ViewResult AddMoneyOnPay()
{
Onpay onpay = new Onpay();
onpay.convert = "yes";
onpay.pay_mode = "fix";
onpay.price_final = "true";
return View(onpay);
}
View:
#using (Html.BeginForm("AddMoneyOnPay", "Transaction", FormMethod.Post))
{
#Html.ValidationSummary(true)
<fieldset>
<legend>Onpay</legend>
<div class="editor-field">
#Html.EditorFor(model => model.pay_mode)
#Html.ValidationMessageFor(model => model.pay_mode)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.price)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.price)
#Html.ValidationMessageFor(model => model.price)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.currency)
#Html.ValidationMessageFor(model => model.currency)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.pay_for)
#Html.ValidationMessageFor(model => model.pay_for)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.md5)
#Html.ValidationMessageFor(model => model.md5)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.convert)
#Html.ValidationMessageFor(model => model.convert)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.url_success)
#Html.ValidationMessageFor(model => model.url_success)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.url_fail)
#Html.ValidationMessageFor(model => model.url_fail)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.user_email)
#Html.ValidationMessageFor(model => model.user_email)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.note)
#Html.ValidationMessageFor(model => model.note)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.one_way)
#Html.ValidationMessageFor(model => model.one_way)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.price_final)
#Html.ValidationMessageFor(model => model.price_final)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.direct_no)
#Html.ValidationMessageFor(model => model.direct_no)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
action POST
[HttpPost]
public ViewResult AddMoneyOnPay(Onpay onpay)
{
string secretKEy = "fH12312IO";
onpay.md5 = GetHash(string.Format("{0};{1};{2};{3};{4}", onpay.pay_mode, onpay.price, onpay.currency, onpay.pay_for, onpay.convert, secretKEy));
//SEND POST to url http://paysite.ru/blablabla
}
Have your AddMoneyOnPay method return an ActionResult and then write:
return Redirect(returnUrl);

Resources