Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
The previous step shows how to create a gadget that can show messages in the database. This step shows how to put the messages in.
AJAX lets you post information from the dashboard.
<%@ Import Namespace="EPiServer.Shell.Web.Mvc.Html" %>
<div class="epi-defaultPadding">...</div>
<hr />
<% Html.BeginGadgetForm("Save"); %>
<input name="text" />
<%= Html.AcceptButton() %>
<% Html.EndForm(); %>
The view renders a form with a text input field and a Submit button. Because the example has a gadget form, the form is serialized and posted using jQuery.ajax. The results of the Save action replace any existing content in the gadget.
The controller accepts the posted message and stores it in the store. The returned view takes the place of the existing view in the gadget area. The mapping of the posted message string to input parameters is a feature of ASP.NET MVC.
public ActionResult Save(string text)
{
// store the posted message
Message message = new Message();
message.Text = text;
message.From = User.Identity.Name;
message.Sent = DateTime.Now;
store.Save(message);
var messages = GetRecentMessages();
return View("Index", messages);
}
IList<Message> GetRecentMessages()
{
return (from m in store.Items<Message>()
where m.Sent > DateTime.Now.AddMinutes(-1)
orderby m.Sent
select m).ToList();
}
Last updated: Nov 25, 2015