I have a dinamically generated dropdownlist and a static textbox, which values I need to use in a controller action, how, or what is the best way to this? or what are my possibilities?
<h2>Content Type Creation</h2>
@using(Html.BeginForm("CreateContentType", "ContentType"))
{
@Html.DropDownList("ContentTypeList", new SelectList(Model, "Id", "Name"))
<input type="text" id="contentTypeName" />
}
[SharePointContextFilter]
public ActionResult Index() //Index fills the dropdown
{
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var ctx = spContext.CreateUserClientContextForSPHost())
{
ContentTypeCollection contentTypes = ctx.Web.ContentTypes;
ctx.Load(contentTypes);
ctx.ExecuteQuery();
return View(contentTypes);
}
}
[SharePointContextFilter]
[HttpPost]
public ActionResult CreateContentType(string parentContentTypeId, string contenttypeName)
{
// Create New Content Type
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var ctx = spContext.CreateUserClientContextForSPHost())
{
Guid fieldId = Guid.NewGuid();
string ctId = string.Format("{0}00{1}", parentContentTypeId, contenttypeName);
// Do not re-create it
if (!ctx.Web.ContentTypeExistsByName(contenttypeName))
{
ctx.Web.CreateContentType(contenttypeName, ctId, "Contoso Content Types");
}
else
{
ViewBag["Message"] = string.Format("Content type with given name and/or ID already existed. Name - {0} ID - {1}", contenttypeName, ctId);
}
}
return View();
}