Hello Community, I'm trying to show message after updating the grid information in controller. Here's my code
CSHTML
@(Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/MainPage/UrlDatasource").Adaptor("UrlAdaptor").UpdateUrl("/MainPage/Update"); }).ActionComplete("complete").Columns(col =>
{ col.Field("Id").HeaderText("Id").IsPrimaryKey(true).ValidationRules(new { required = true}).Width("100").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("UserName").HeaderText("UserName").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).AllowPaging().PageSettings(page => page.PageCount(2)).EditSettings(edit => {
edit.AllowEditing(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List() { "Edit"}).Render())
I tried to use ActionComplete but it's not working
Controller
public object UrlDatasource(DataManagerRequest dm)
{
string qs = "SELECT Id, UserName FROM dbo.sys_UsersProfile ORDER BY Id";
if (dm.Take != 0)
{
qs = qs + " OFFSET " + dm.Skip + "ROWS FETCH NEXT " + dm.Take + " ROWS ONLY; ";
}
else
{
qs = qs + "; ";
}
DataSet data = CreateCommand(qs, cons);
sys_UsersProfile = data.Tables[0].AsEnumerable().Select(r => new vw_UserAccount_DataInformation
{
Id = r.Field("Id"),
UserName = r.Field("UserName"),
}).ToList(); // Here we convert dataset into list
IEnumerableDataSource = sys_UsersProfile;
if (con.State != ConnectionState.Open)
con.Open();
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM dbo.sys_UsersProfile", con);
Int32 count = (Int32)comm.ExecuteScalar();
con.Close();
return Json(new { result = DataSource, count = count });
}
public class DataResult
{
public IEnumerable result { get; set; }
public int count { get; set; }
}
public ActionResult Update(vw_UserAccount_DataInformation value)
{
SqlCommand cmd = new SqlCommand("update dbo.sys_UsersProfile set UserName=@UserName where Id=@Id", con);
if (con.State != ConnectionState.Open)
con.Open();
cmd.Parameters.AddWithValue("@Id", value.Id);
cmd.Parameters.AddWithValue("@UserName", value.UserName);
cmd.ExecuteNonQuery();
con.Close();
return PartialView("_DialogEditPartialSelected_UserMaintenanceView", value);
}
_DialogEditPartialSelected_UserMaintenanceView
I'm using a dialog template view to edit the datagrid
<h2>_DialogEditPartialSelected_UserMaintenanceView</h2>
<div>
<div>
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
@Html.TextBox("Id", Model.Id.ToString(), new { disabled = true })
<span class="e-float-line"></span>
@Html.Label("Id", "Id", new { @class = "e-float-text e-label-top" })
</div>
</div>
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
@Html.TextBox("UserName", Model.UserName.ToString())
<span class="e-float-line"></span>
@Html.Label("UserName", "User Name", new { @class = "e-float-text e-label-top" })
</div>
</div>
</div>
</div>
@Html.EJS().ScriptManager()
|
@Html.EJS().Grid("CommandColumn").ActionComplete(“actionComplete”).DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").InsertUrl("/Home/Insert").UpdateUrl("/Home/Update").RemoveUrl("/Home/Delete").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = true }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("150").ValidationRules(new { required = true, minLength = 3 }).Add();
col.Field("Freight").HeaderText("Freight").Width("120").EditType("numericedit").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();
col.Field("ShipCountry").HeaderText("Ship Country").EditType("dropdownedit").Width("150").Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true). Mode(Syncfusion.EJ2.Grids.EditMode.Dialog). Template("#dialogtemplate"); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
function actionComplete(args) {
if (args.requestType === 'save') {
alert('record saved');
}
</script>
|
I have another problem about the layout of the dialog box how can I change the layout design from this unorganized dialog layout to this inline form layout
.cshtml
@(Html.EJS().Grid("Grid").DataSource(dataManager =>{ dataManager.Url("/MainPage/UrlDatasource").Adaptor("UrlAdaptor").UpdateUrl("/MainPage/Update");}).Columns(col =>{ col.Field("Id").HeaderText("Id").IsPrimaryKey(true).ValidationRules(new { required = true }).Width("100").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ApplicationId").IsPrimaryKey(true).HeaderText("Application Id").ValidationRules(new { required = true }).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("UserName").HeaderText("User Name").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Password").HeaderText("Password").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("RecIdNo").HeaderText("Empl_RecIdNo").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("EmpNo").HeaderText("EmplIDNo").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Account_Status").HeaderText("Account Status").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Login_StatusCode").IsPrimaryKey(true).HeaderText("Login Status Code").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("LastLoginIn_Date").IsPrimaryKey(true).HeaderText("Last LoginIn Date").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("AccessLevel").HeaderText("AccessLevel").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("IsAnonymous").HeaderText("Is Anonymous").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("FirstName").HeaderText("First Name").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("LastName").HeaderText("Last Name").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("MiddleName").HeaderText("Middle Name").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("State").HeaderText("State").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add()
col.Field("Email").HeaderText("Email").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("EmailConfirmed").HeaderText("EmailConfirmed").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("SecurityStamp").HeaderText("SecurityStamp").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("PhoneNumber").HeaderText("PhoneNumber").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("PhoneNumberConfirmed").HeaderText("PhoneNumberConfirmed").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CreatedDate").HeaderText("CreatedDate").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Created_By").HeaderText("Created_By").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ModifiedDate").HeaderText("ModifiedDate").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Modified_By").HeaderText("Modified_By").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("inWorkStation").HeaderText("inWorkStation").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).AllowPaging().PageSettings(page => page.PageCount(2)).EditSettings(edit => { edit.AllowEditing(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List() { "Edit"}).Render())
|
addTemplate.cshtml
@using Syncfusion.EJ2
<div>
<div class="form-row">
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
@Html.TextBox("OrderID")
<span class="e-float-line"></span>
@Html.Label("OrderID", "Order ID", new { @class = "e-float-text e-label-top" })
</div>
</div>
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
@Html.TextBox("CustomerID")
<span class="e-float-line"></span>
@Html.Label("CustomerID", "Customer ID", new { @class = "e-float-text e-label-top" })
</div>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
@Html.EJS().NumericTextBox("Freight").Format("C2").Placeholder("Freight").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).Render()
</div>
<div class="form-group col-md-6">
@Html.EJS().DatePicker("OrderDate").Placeholder("Order Date").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).Render()
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
@Html.EJS().DropDownList("ShipCountry").Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "ShipCountry", Value = "ShipCountry" }).Placeholder("Ship Country").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).DataSource((IEnumerable<object>)@ViewBag.datasource).Render()
</div>
<div class="form-group col-md-6">
@Html.EJS().DropDownList("ShipCity").Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "ShipCity", Value = "ShipCity" }).Placeholder("Ship City").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).DataSource((IEnumerable<object>)@ViewBag.datasource).Render()
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<div class="e-float-input e-control-wrapper">
@Html.TextArea("ShipAddress")
<span class="e-float-line"></span>
@Html.Label("ShipAddress", "Ship Address", new { @class = "e-float-text e-label-top" })
</div>
</div>
</div>
</div>
@Html.EJS().ScriptManager() |
Hello, the problem is I can't render the partial view for the dialog box based on my sample code it only loads by using .Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); to use the dialog I can't use an ajax .Template("#dialogtemplate") to render a partial view
I'm trying to use an Ajax call to load in partial views on click of a row within the grid however it seems the partial view is not rendering. What did I missed
Index.cshtml
@{ViewBag.Title = "DialogTemplateEdit";
}
@using Syncfusion.EJ2
@Html.EJS().Grid("FlatGrid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").UpdateUrl("/Home/editpartial"); }).ActionComplete("actionComplete")
.Columns(col =>
{col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).ValidationRules(new { required = true, minLength = 3 }).Width("100").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCity").HeaderText("Ship City").EditType("dropdownedit").Width("120").Add(); }).
AllowPaging().PageSettings(page => page.PageCount(2)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog).Template("#dialogtemplate"); }).Toolbar(new List() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
function actionComplete(args) {
if (args.requestType === 'beginEdit') {
args.dialog.header = 'Edit';
args.dialog.height = '400px';
var ajax = new ej.base.Ajax({
@*url: "@Url.Action("editpartial", "Home")",*@ //render the partial view
url: "/Home/editpartial",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send().then(function (data) {
$("#dialogTemp").html(data); //Render the edit form with selected record
args.form.elements.namedItem('OrderID').focus();
//var dialogObj = document.getElementById("DialogTemplateEdit").ej2_instances[0];
//dialogObj.show();
}).catch(function (xhr) {
console.log(xhr);
});
}
if (args.requestType === 'add') {
args.dialog.header = 'Add Dialog';
var ajax = new ej.base.Ajax({
url: "/Home/AddPartial", //render the partial view
type: "POST",
contentType: "application/json",
});
ajax.send().then(function (data) {
$("#dialogTemp").html(data); //Render the edit form with selected record
args.form.elements.namedItem('OrderID').focus();
}).catch(function (xhr) {
console.log(xhr);
});
}
}
</script>
<div id="dialogtemplate">
</div>
In Index.cshtml view I used ajax to call the partial view editpartial.cshtml from the home folder however no rendering happens and it display nothing in the dialog template.
This is the Partial View that is not rendering
editpartial.cshtml
@model AspNetMvc5.Models.DialogTemplateModel
@*//define the model for store the model values*@@using Syncfusion.EJ2
@Html.TextBox("OrderID", Model.OrderID.ToString(), new { disabled = true })@Html.Label("OrderID", "Order ID", new { @class = "e-float-text e-label-top" })
@Html.TextBox("CustomerID", Model.CustomerID.ToString())@Html.Label("CustomerID", "Customer Name", new { @class = "e-float-text e-label-top" })
@Html.EJS().NumericTextBox("Freight").Value(Model.Freight).Format("C2").Placeholder("Freight").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).Render()
@Html.EJS().DatePicker("OrderDate").Value(Model.OrderDate).Placeholder("Order Date").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).Render()
@Html.EJS().DropDownList("ShipCountry").Value(Model.ShipCountry).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "ShipCountry", Value = "ShipCountry" }).Placeholder("Ship Country").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).DataSource((IEnumerable)@ViewBag.datasource).Render()
@Html.EJS().DropDownList("ShipCity").Value(Model.ShipCity).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "ShipCity", Value = "ShipCity" }).Placeholder("Ship City").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).DataSource((IEnumerable)@ViewBag.datasource).Render()
@Html.TextArea("ShipAddress", Model.ShipAddress)@Html.Label("ShipAddress", "Ship Address", new { @class = "e-float-text e-label-top" })
@Html.EJS().ScriptManager()This is the sample output with .Template("#dialogtemplate")
(It doesn't load the form inside of the partial view)
|
<script>
function actionComplete(args) {
if (args.requestType === 'beginEdit') {
args.dialog.header = 'Edit';
args.dialog.height = '400px';
var ajax = new ej.base.Ajax({
url: "/Home/editpartial",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send().then(function (data) {
$("#dialogTemp").html(data); //Render the edit form with selected record
args.form.elements.namedItem('OrderID').focus();
}).catch(function (xhr) {
console.log(xhr);
});
}
. . .
}
</script>
<script id='dialogtemplate' type="text/x-template">
<div id="dialogTemp">
</div>
</script> |
Hello,
I did
|
<div class="form-row">
<div class="form-group col-md-12">
@Html.EJS().DropDownList("ShipCountry").Value(Model.ShipCountry).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "ShipCountry", Value = "ShipCountry" }).Placeholder("Ship Country").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).DataSource((IEnumerable<object>)@ViewBag.datasource).Render()
</div>
<div class="form-group col-md-12">
@Html.EJS().DropDownList("ShipCity").Value(Model.ShipCity).Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "ShipCity", Value = "ShipCity" }).Placeholder("Ship City").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).DataSource((IEnumerable<object>)@ViewBag.datasource).Render()
</div>
</div> |
Hello,
I did
|
namespace mvc_ej2.Controllers
{
public class HomeController : Controller
{
public static List<OrdersDetails> orddata = new List<OrdersDetails>();
public ActionResult Editpartial(DialogTemplateModel value)
{
ViewBag.datasource = orddata;
return PartialView("editpartial", value);
}
// for updating action
public ActionResult Update(CRUDModel<OrdersDetails> myObject)
{
. . .
return Json(ord.Value);
}
} |
|
@Html.EJS().Grid("FlatGrid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").UpdateUrl("/Home/Update"); }).ActionComplete("actionComplete").Columns(col =>
{
. . .
}).AllowPaging().PageSettings(page => page.PageCount(2)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog).Template("#dialogtemplate"); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
function actionComplete(args) {
if (args.requestType === 'beginEdit') {
var ajax = new ej.base.Ajax({
url: "/Home/editpartial",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send().then(function (data) {
$("#dialogTemp").html(data); //Render the edit form with selected record
. . .
}).catch(function (xhr) {
console.log(xhr);
});
}
}
</script>
|
Hello,
I tried to use the example code however still no display form in my dialog template
Here's the sample source code: https://drive.google.com/file/d/1fE2V-uQAEh34y9nhA5rDL394Z6yfzru5/view?usp=sharing
|
Index.cshtml
<script id='dialogtemplate' type="text/x-template"> // Need to use script tag to bind the dialog template properly in the Grid component.
<div id="dialogTemp">
</div>
</script>
|
|
Editpartial.cshtml
@model AspNetMvc5.Models.DialogTemplateModel
@*//define the model for store the model values*@
@using Syncfusion.EJ2
<div> // avoid using the script tag inside the edit or add partial page
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
@Html.TextBox("OrderID", Model.OrderID.ToString(), new { disabled = true })
<span class="e-float-line"></span>
@Html.Label("OrderID", "Order ID", new { @class = "e-float-text e-label-top" })
</div>
</div>
<div class="form-group col-md-6">
<div class="e-float-input e-control-wrapper">
@Html.TextBox("CustomerID", Model.CustomerID) // avoid type casting for null values
<span class="e-float-line"></span>
@Html.Label("CustomerID", "Customer Name", new { @class = "e-float-text e-label-top" })
</div>
</div> |
|
HomeController.cs
public ActionResult Update(DialogTemplateModel value)
{
SqlCommand cmd = new SqlCommand("update dbo.Orders set ShipCountry=@ShipCountry,ShipCity=@ShipCity where OrderID=@OrderID", con);
if (con.State != ConnectionState.Open)
con.Open();
cmd.Parameters.AddWithValue("@OrderID", value.OrderID);
cmd.Parameters.AddWithValue("@ShipCountry", value.ShipCountry);
cmd.Parameters.AddWithValue("@ShipCity", value.ShipCity);
cmd.ExecuteNonQuery();
con.Close();
return Json(value);
}
public ActionResult Editpartial(DialogTemplateModel value)
{
return PartialView("editpartial", value);
}
|
|
Index.cshtml
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").UpdateUrl("/Home/Update"); }).ActionComplete("actionComplete").Columns(col =>
|