How can I change field value by using MVC?
I have a form in view like this and defined Controll Name and Action in ViewRendering Item.
@using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, System.Web.Mvc.FormMethod.Post))
{
@Html.Sitecore().FormHandler("Components", "testController")
@Html.DropDownListFor(model => model.TypeList, new List<SelectListItem>
{
new SelectListItem{Text="Enable", Value="True", Selected = (isSet ? true : false)},
new SelectListItem{Text="Disable", Value="False", Selected = (!isSet ? true : false)}
})
<input type="submit" name="submit" value="submit"/>
}
What I want to do is when "submit" clicked, controller gets the form data and update field value in Sitecore in EditorMode.
How Can I do??
In Controller, this is what I'm thinking:
public class Components: SitecoreController
{
public ActionResult testController()
{
if (submit clicks) {
ComponentModel ob = new ComponentModel();
ob.Initialize(RenderingContext.Current.Rendering);
string selectedValue = selectedValue from View;
ob.item.Editing.BeginEdit();
using(new EditContext())
{
ob.CheckBoxField.Checked = (selectedValue == "True" ? true : false);
}
ob.item.Editing.EndEdit();
return PartialView(ob);
}
return PartialView();
}
}