ASP.NET - MVC 3 RAZOR : Pass a string value from Controller Grid Action to View

Asked By chie_hitech y on 22-May-12 12:11 PM
Earn up to 30 extra points for answering this tough question.
Hi All,

I am using Telerik MVC Grid and performing an Ajax Binding.  Below is the code in my CSHTML file.

@(Html.Telerik().Grid(Model.customer)
      .Name("GridCustomer")
      .DataKeys(keys => keys.Add(doc => doc.CustId))
      .ToolBar(commands => commands.Insert().ImageHtmlAttributes(new { style = "margin-left:0" }))

      .DataBinding(dataBinding =>
        {
          dataBinding.Ajax()
          .Update("Update", "Test")
          .Delete("Delete", "Test")
          .Insert("Insert", "Test");
        })
      .Columns(columns =>
      {
        //columns.Bound(doc => doc.CustId).Template(@<text>  @Html.Telerik().DropDownList().Name("ddl").BindTo(new SelectList(Model.ToList(), "CustId", "CustName"))</text>);
        columns.Bound(doc => doc.CustName);
        columns.Bound(doc => doc.CustCity).Width(100);
        columns.Bound(doc => doc.CustAddress).Width(150);
        columns.Command(commands => { commands.Edit(); });
        columns.Command(commands => { commands.Delete(); });
      })
      .Editable(editing => editing.Mode(GridEditMode.InLine))
      
 )

In Controller I have my Grid Action.

 [AcceptVerbs(HttpVerbs.Post)]
 [GridAction]
 public ActionResult Insert(FormCollection frmcl)
{
 // Insert code goes here //
}

Now, I have a string value to check if the Insert is success or fail. This value comes from my Data Access layer(Service). I have a property for this(in my Model)
I want to show this message in my view.It may be displayed as a Label or a popup. But since the GridAction does not refresh the entire view,I am unable to pass the string message.  
In this scenario, I cannot use a JSONResponse as its a GridAction.
I even tried placing my Grid in a Partial View and using the following code :


@model TelerikMvcApplication2.Models.Example
@{
    ViewBag.Title = "Index";
 
}
<h2>
    Index</h2>
  @Html.LabelForModel(Model.errorMessage)
@Html.Partial("_resultSet");

Please suggest how to solve this issue.

Please let me know if there is a work-around for this.

Thanks in advance. 
Jitendra Faye replied to chie_hitech y on 23-May-12 12:10 AM
I think this is because of -callbacks

YOu are missing callbacks

Refer this link -

http://forums.asp.net/t/1806024.aspx/1?how+to+show+message+to+view+from+controller+action+method+
chie_hitech y replied to Jitendra Faye on 23-May-12 04:47 AM
Thanks for the reply.
Can we make an Ajax call for a GridAction?
I am not clear as to how to do this.
Can you please provide an example...

Thank You
[)ia6l0 iii replied to chie_hitech y on 28-May-12 09:23 AM
When your Action "Insert" returns a View, the control goes to the View that is rendered. In this you should be able to grab the value either from the model, or from objects like ViewBag. Set the values in ViewBag, and then grab the values on the client side. 

Hope this helps.