How to save information from UI to mongoDB collection - c#

I'm currently looking for this, i have a modal that contains some textbox, user have to fill them and then i'd like to save the information inside a collection in mongo. A class ConnectionHandler.cs is used to connect to database and we are using mongoentities. So i have this :
using MongoDB.Driver;
using Project.My.Core.Entities.MongoEntities;
namespace Project.My.Core
{
public class ConnectionHandler<T> where T : IMongoEntity
{
public MongoCollection<T> MongoCollection { get; private set; }
public ConnectionHandler()
{
var connectionString = "mongodb://localhost";
//// Acceder à la chaine de connection
var mongoClient = new MongoClient(connectionString);
//// Acceder au serveur
var mongoServer = mongoClient.GetServer();
//// Acceder à la BD
const string databaseName = "MyDB";
var db = mongoServer.GetDatabase(databaseName);
//// Acceder aux collection la BD (tables en langage relationnel...)
MongoCollection = db.GetCollection<T>(typeof(T).Name);
}
}
}
My modal content is inside a partial view like this :
#using Project.My.Web.Administration.Models
#model GarantieViewModel
<div id ="userinput" class="form-panel-modify">
<div class="form-horizontal style-form">
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.NomUser, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(m => m.UserInformationViewModel.NomUser, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.PrenomUser, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(m => m.UserInformationViewModel.PrenomUser, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.EntrepriseUser, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(m => m.UserInformationViewModel.EntrepriseUser, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.EmailUser, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(m => m.UserInformationViewModel.EmailUser, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.TelephoneUser, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(m => m.UserInformationViewModel.TelephoneUser, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.whoareyou, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.EnumDropDownListFor(m => m.UserInformationViewModel.whoareyou, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.mutuelle45, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.EnumDropDownListFor(m => m.UserInformationViewModel.mutuelle45, new { #class = "form-control" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(m => m.UserInformationViewModel.NumeroOrias, new { #class = "col-sm-d col-sm-3 control-label" })
<div class="col-sm-8">
#Html.TextBoxFor(m => m.UserInformationViewModel.NumeroOrias, new { #class = "form-control" })
</div>
</div>
</div>
</div>
<div style="margin-top:50px;">
<input type="submit" disabled="true" class="btn btn-default" style="color: #ffffff;background-color:#48bcb4;border-color: #48bcb4;">
</div>
And finally my modal is here :
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" style="height:650px;width:600px;text-align:center">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Informations</h4>
<p><b>Pour lancer la comparaison vous devez d'abord renseigner vos informations</b></p>
</div>
#Html.Partial("_ModalContent")
</div>
</div>
</div>
So, after looking everywhere i can't do what i want. I just want the information of my modal content to go inside a collection named "UserInformation" for example.
If someone could help with this it would be great ! Thanks.

Related

ASP.NET HTML - Textboxes are extremely close together and need help putting space in between them

#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<h4>Send your comments.</h4>
<hr />
<div class="form-group">
#Html.LabelFor(m => m.FromName, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.FromName, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.FromName)
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(m => m.FromEmail, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.FromEmail, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.FromEmail)
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(m => m.Message, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Message, new { #class = "form-control" })
#Html.ValidationMessageFor(m => m.Message)
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Send" />
</div>
</div>
}
I have tried using clearfix, as well as modifying the css margins in form-group. If anyone has any suggestions, feel free. Program works perfectly, just the formatting that is off.
You seem to be using clearfix in the wrong place?
Just add it along side form-group
<div class="form-group clearfix">
Try either one will solve the problem.
Add the class form-horizontal to the form
or
Add the class row to the <div class="form-group">

How to add a [create] partial view inside a details view or any other with parameters?

I am trying to add a partial view [Create view] inside a details view, capturing the ID as parameter, but it always displays a different error.
I have been looking for a solution and the reason why it fails but there is no a good answer or good tutorial to make this possible.
Details view:
#model HumanForceMVC1._1.HF_Projects
#{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="slim-mainpanel">
<div class="container">
<div class="slim-pageheader">
<ol class="breadcrumb slim-breadcrumb">
<li class="breadcrumb-item">Home</li>
<li class="breadcrumb-item">Create new task</li>
</ol>
<!-- Modal -->
<div class="modal fade" id="addNewTaskModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
#*#Html.RenderPartial("AddTaskToProject", Model.HF_Tasks, new ViewDataDictionary { { Pid = Model.Id } })*#
#Html.Partial("AddTaskToProject", Model.HF_Tasks, new ViewDataDictionary { { "Pid", Model.Id } })
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
My controller:
[HttpPost]
public ActionResult AddTaskToProject(int Pid, HF_Tasks Item)
{
using (var context = new HumanForceDBEntities())
{
HF_Tasks myTask = new HF_Tasks();
myTask = Item;
myTask.ProjectAssigned = Pid;
myTask.TaskStatus = 2;
myTask.TaskDate = DateTime.Now;
context.HF_Tasks.Add(myTask);
context.SaveChanges();
return PartialView();
}
}
My Partial View:
#using (Html.BeginForm())
{ #Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>HF_Tasks</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(model => model.TaskName, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.TaskName, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.TaskName, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.TaskDescription, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.TaskDescription, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.TaskDescription, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.PersonAssigned, "PersonAssigned", htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownList("PersonAssigned", null, htmlAttributes: new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.PersonAssigned, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
Please, somebody who can help me with this.
I appreciate in advance.
You need to add the #model ...HF_Tasks in the partial view on the top similar to what you have in the detail view.

Button Horizontally inline with text boxes Razor View

I Have the following form on a view
#using (Html.BeginForm("AddInterest", "Club", FormMethod.Post))
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
<div class="row">
<div class="col-md-8">
<div class="well bs-component">
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<h3>Not listed? - Add extras here</h3>
</div>
</div>
#Html.HiddenFor(model => model.ClubTypeId)
#Html.HiddenFor(model => model.ClubId)
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group">
<div class="row col-md-offset-1 col-md-11">
<div class="col-md-4">
#Html.LabelFor(model => model.InterestName, htmlAttributes: new { #class = "control-label" })
#Html.EditorFor(model => model.InterestName, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.InterestName, "", new { #class = "text-danger" })
</div>
<div class="col-md-5">
#Html.LabelFor(model => model.Description, htmlAttributes: new { #class = "control-label" })
#Html.EditorFor(model => model.Description, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Description, "", new { #class = "text-danger" })
</div>
<input type="submit" value="Add" class="btn btn- success" />
</div>
</div>
</div>
</div>
</div>
</div>
}
Everything is good apart from the submit button sits inline horizontally with the labels not the editor boxes, how can I get it to drop down?
i.e.
Label Label
Text Box Text Box Button
NOT
Label Label Button
Text Box Text Box
Its currently showing like this:
You should recreate your form following this pattern:
<div class="form-group">
#Html.LabelFor(model => model.InterestName, htmlAttributes: new { #class = "col-md-4 control-label" })
<div class="col-md-8">
#Html.EditorFor(model => model.InterestName, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.InterestName, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Description, htmlAttributes: new { #class = "col-md-4 control-label" })
<div class="col-md-8">
#Html.EditorFor(model => model.Description, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Description, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
<input type="submit" value="Add" class="btn btn-success" />
</div>
</div>
More information at http://getbootstrap.com/css/#forms-horizontal
Edit
If you want them inline vertically:
<form class="form-inline">
<div class="form-group">
#Html.LabelFor(model => model.InterestName)
#Html.EditorFor(model => model.InterestName, new { htmlAttributes = new { #class = "form-control" } })
</div>
<div class="form-group">
#Html.LabelFor(model => model.Description)
#Html.EditorFor(model => model.Description, new { htmlAttributes = new { #class = "form-control" } })
</div>
<input type="submit" value="Add" class="btn btn-success" />
</form>
More information at http://getbootstrap.com/css/#forms-inline
Edit 2
If you want them inline horizontally but in two columns and submit button aligned to the right:
<form>
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(model => model.InterestName)
#Html.EditorFor(model => model.InterestName, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(model => model.Description)
#Html.EditorFor(model => model.Description, new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<button type="submit" class="btn btn-default" style="margin-top: 25px;">Add</button>
</div>
</div>
</form>

Activate method in form

I want to submit a single text field in a form. I have this view:
#model SenecaFormsServer.Areas.Dashboard.Models.EditProductModel
#using SenecaFormsServer.Areas.Dashboard.Models
#using Seneca.SfsLib.Connectors
<div id="ConnectorSettings-MAIL_PRODUCT_HANDLERS">
<h4>#Resources.Entity.Product.SettingsForConnector: Mail product handlers</h4>
#{
MailProductHandlersModel mailModel = Model.ConnectorModels["MAIL_PRODUCT_HANDLERS"] as MailProductHandlersModel;
}
<div class="form-group">
#Html.Label(Resources.Entity.Product.Sender, new { #class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.Editor("MailProductHandlers_sender", new { htmlAttributes = new { #class = "form-control", #Value = mailModel.Sender, #placeholder = Model.CustomerConfig.DefaultSenderAddress } })
</div>
</div>
<div class="form-group">
#Html.Label(Resources.Entity.Product.MailSubject, new { #class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.Editor("MailProductHandlers_subject", new { htmlAttributes = new { #class = "form-control", #Value = mailModel.Subject } })
</div>
</div>
<!--
<div class="form-group">
#Html.Label("Reply to form submitter", new { #class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.CheckBox("MailProductHandlers_replytoFormSubmitter", new { htmlAttributes = new { #class = "form-control" } })
</div>
</div>
-->
<div class="form-group">
#Html.Label(Resources.Entity.Product.MailMessage, new { #class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.EditorFor(model => mailModel.Message, new { htmlAttributes = new { #class = "form-control tiny-mce", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })
#Html.ValidationMessageFor(model => mailModel.Message)
#*#Html.TextArea("MailProductHandlers_message", mailModel.Message, new { #class = "form-control", #rows = 15 })*#
</div>
</div>
<div class="form-group">
#Html.Label(Resources.Entity.Product.GeneratePDF, new { #class = "text-bold control-label col-md-2" })
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.Label(Resources.Entity.Product.GeneratePDFYes) #Html.RadioButtonFor(model => model.IsChecked, true, new { #checked = "checked", #class = "pdfchecker" })
#Html.Label(Resources.Entity.Product.GeneratePDFNo) #Html.RadioButtonFor(model => model.IsChecked, false, new { #class = "pdfchecker" })
</div>
</div>
<div class="form-group">
<div id="hideLable">
#Html.Label(Resources.Entity.Product.PdfMessage, new { #class = "text-bold control-label col-md-2" })
</div>
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { #class = "form-control tiny-mce", #id = "mceu_61", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })
#Html.ValidationMessageFor(model => mailModel.PdfMessage)
</div>
</div>
#using (Html.BeginForm("GeneratePDFFromHtml", "Product", FormMethod.Post)) {
#Html.AntiForgeryToken()
<div class="col-xs-12 padding-bottom-10">
#*<i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF *#
<button type="submit" value="Save" class="btn btn-success"><i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF</button>
</div>
}
And I want to submit this part:
#using (Html.BeginForm("GeneratePDFFromHtml", "Product", FormMethod.Post)) {
#Html.AntiForgeryToken()
<div class="col-xs-12 padding-bottom-10">
#*<i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF *#
<button type="submit" value="Save" class="btn btn-success"><i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF</button>
</div>
}
and this is the action method:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult GeneratePDFFromHtml(EditProductModel model, string data, string designId)
{
string customerSchema = SfsHelpers.StateHelper.GetSchema();
//TemplateLibraryEntry entry = GetTemplateLibraryEntry(designId, customerSchema);
SubmittedForm sf = new SubmittedForm();
string schema = requestSchema;
customer_DbConnection db = new customer_DbConnection();
RenderFormController renderController = new RenderFormController();
renderController.GeneratePdf(data, db,sf);
//return RedirectToAction(model.DesignId, "Prdocut/Edit");
return Content("It works");
}
</div>
but the action method is not been triggered.
How to trigger the action method?
There has be created a PDF file from this textfield:
#using (Html.BeginForm("GeneratePDFFromHtml", "Product", null, FormMethod.Post, new { enctype = "multipart/form-data" })) {
#Html.AntiForgeryToken()
<div class="form-group">
<div id="hideLable">
#Html.Label(Resources.Entity.Product.PdfMessage, new { #class = "text-bold control-label col-md-2" })
</div>
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { #class = "form-control tiny-mce", #id = "mceu_61", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })
#Html.ValidationMessageFor(model => mailModel.PdfMessage)
</div>
</div>
<div class="col-xs-12 padding-bottom-10">
<i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF
#*<button type="submit" value="Save" class="btn btn-success"><i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF</button>*#
</div>
}
and this is also the action method that has to been triggered and create the PDF file. But the method is not been triggered in the controller
The problem is that it is a partial view. So I solved like this:
Jquery:
$(document).ready(function () {
$('#btnGeneratePDF').click(function () {
var form = document.createElement("form");
form.setAttribute("GeneratePDFFromHtml", "post");
form.setAttribute("action", "GeneratePDFFromHtml");
form.setAttribute("target", "_blank");
var hiddenField = document.createElement("btnGeneratePDF");
//hiddenField.setAttribute("name", "search");
//hiddenField.setAttribute("value", "product1,product2");
hiddenField.setAttribute("type", "hidden");
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
});
});
and the view looks like now this:
<form method="post" id="form" name="form" action="#Url.Action("GeneratePDFFromHtml", "Product")" enctype="multipart/form-data">
<fieldset>
<div class="form-group">
<div id="hideLable">
#Html.Label(Resources.Entity.Product.PdfMessage, new { #class = "text-bold control-label col-md-2" })
</div>
<div class="col-lg-6 col-md-8 col-sm-10 ">
#Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { #class = "form-control tiny-mce", #id = "mceu_61", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })
#Html.ValidationMessageFor(model => mailModel.PdfMessage)
</div>
</div>
<div class="col-xs-12 padding-bottom-10">
#*<i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF *#
<button type="submit" value="Create" class="btn btn-success" id="btnGeneratePDF" name="btnGeneratePDF" formtarget="_blank" onclick="GeneratePDFFromHtml()"><i class="fa fa-fw fa-check"></i> #Resources.Action.Navigation.GeneratePDF</button>
</div>
</fieldset>
</form>
but the url is now like this, after I press on the button:
http://localhost:51098/Dashboard/Product/Edit/GeneratePDFFromHtml?
what is ofcourse not correct. so how to trigger the method in the controller?
I get also this warning: Uncaught ReferenceError: GeneratePDFFromHtml is not defined

MVC RenderPartial Shared Strongly Typed View

I have a Strongly Types Partial View that I am trying to render from another Partial View
#{ Html.RenderPartial("Days", Model.DaysOpen, new ViewDataDictionary()); }
I have been folling advice based on the below
ASP.NET MVC, strongly typed views, partial view parameters glitch
It allows me to create the parent(Centre) but does not create the Child (owned) Days entity.
Can anyone offer any advice
Details.cshtml
#model RCCMS.ObjectModel.Entities.Centre
#using (Html.BeginForm(null, null, FormMethod.Post, new { #class = "form-horizontal", Role = "form" }))
{
#Html.ValidationSummary("Please correct the following errors:-")
<div id="HiddenFields">
#Html.HiddenFor(m => m.RowVersion)
</div>
<fieldset>
<div class="form-group">
#Html.LabelFor(model => model.Name, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Name, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Name, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Address1, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Address1, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Address1, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Address2, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Address2, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Address2, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Address3, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Address3, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Address3, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Town, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Town, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Town, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.County, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.County, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.County, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Postcode, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Postcode, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Postcode, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Uprn, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Uprn, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Uprn, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Lunch, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.Lunch, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.Lunch, "*")
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.VoluntaryContribution, new { #class = "col-md-2 control-label" })
<div class="col-md-5">
#Html.TextBoxFor(model => model.VoluntaryContribution, new { #class = "form-control" })
</div>
<div class="col-md-1">
#Html.ValidationMessageFor(model => model.VoluntaryContribution, "*")
</div>
</div>
#{ Html.RenderPartial("Days", Model.DaysOpen, new ViewDataDictionary()); }
<div class="col-md-offset-2">
<input type="submit" name="submit" value="Save" class="btn btn-primary"/>
<input type="submit" id="cancel" name="submit" value="Cancel" class="btn"/>
</div>
</fieldset>
}
And my Partial View (Days)
#model RCCMS.ObjectModel.Entities.Days
<div class="form-group">
#Html.Label("Days Open", new {#class = "col-md-5 control-label"})
<div class="col-md-10">
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Monday) Monday
#Html.ValidationMessageFor(m => m.Monday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Tuesday) Tuesday
#Html.ValidationMessageFor(m => m.Tuesday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Wednesday) Wednesday
#Html.ValidationMessageFor(m => m.Wednesday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Thursday) Thursday
#Html.ValidationMessageFor(m => m.Thursday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Friday) Friday
#Html.ValidationMessageFor(m => m.Friday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Saturday) Saturday
#Html.ValidationMessageFor(m => m.Saturday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
#Html.CheckBoxFor(m => m.Sunday) Sunday
#Html.ValidationMessageFor(m => m.Sunday, "*")
</label>
</div>
</div>
The create action of the CentreController
public ActionResult Create()
{
if (!Security.HasPemission(Permission.CanCreateCentres)) return View("AccessDenied");
var model = new Centre();
return (IsAjax()) ? (ActionResult)PartialView("Details", model) : View(model);
}

Categories

Resources