I have View like this:
#model MVCApp.Models.User
#{
ViewBag.Title = "EditUser";
}
<h2>Edycja użytkownika</h2>
#using (Ajax.BeginForm("SaveUser", "My", new AjaxOptions { UpdateTargetId = "Result" }))
{
<fieldset>
<legend>Zmień dane użytkownika</legend>
<div id="EditUserForm">
<div>
#Html.LabelFor(m => Model.Login)
#Html.TextBoxFor(m => Model.Login)
</div>
<div>
#Html.LabelFor(m => Model.Password)
#Html.TextBoxFor(m => Model.Password)
</div>
<div>
#Html.LabelFor(m => Model.Name)
#Html.TextBoxFor(m => Model.Name)
</div>
<div>
#Html.LabelFor(m => Model.Surname)
#Html.TextBoxFor(m => Model.Surname)
</div>
<div>
#Html.LabelFor(m => Model.UserRole.Role)
#Html.TextBoxFor(m => Model.UserRole.Role)
</div>
<input type="submit" value="Zapisz zmiany" />
#Html.HiddenFor(m => Model.UserRole)
#Html.HiddenFor(m => Model.UserRoleID)
#Html.HiddenFor(m => Model.UserID)
</div>
</fieldset>
<div id="Result"></div>
#Html.ValidationSummary(true)
}
and method in MyController like this:
[HttpPost]
public ActionResult SaveUser(User user, UserRole role)
{
//code here
}
but object role is not passed, either user.UserRole.
My User model class:
namespace MVCApp.Models
{
public partial class User
{
public User()
{
this.Factures = new HashSet<Facture>();
this.Settings = new HashSet<Setting>();
this.Companies = new HashSet<Company>();
}
public int UserID { get; set; }
public Nullable<int> UserRoleID { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public virtual ICollection<Facture> Factures { get; set; }
public virtual ICollection<Setting> Settings { get; set; }
public virtual UserRole UserRole { get; set; }
public virtual ICollection<Company> Companies { get; set; }
}
}
And Role model class:
namespace MVCApp.Models
{
public partial class UserRole
{
public UserRole()
{
this.Users = new HashSet<User>();
}
public int UserRoleID { get; set; }
public string Role { get; set; }
public virtual ICollection<User> Users { get; set; }
}
}
so, How can I pass models like this, which has other reference types inside?
The following line in your view make no sense
#Html.HiddenFor(m => Model.UserRole)
UserRole is a complex object, and depending on whether you have overridden its .ToString() method, it will render <input ... value="MVCApp.Models.UserRole" /> so when this posts back the DefaultModelBinder is trying to do model.UserRole = "MVCApp.Models.UserRole" which of course fails and the property is therefore null
Remove it, and instead bind to the properties of UserRole that you want posted back - as you have done with #Html.TextBoxFor(m => Model.UserRole.Role). For example #Html.HiddenFor(m => Model.UserRole.UserRoleID) but you already seem to have bound this with #Html.HiddenFor(m => Model.UserRoleID) so it might not be necessay to repeat it.
you can create your own submitting mechanism. Just use $.ajax and pass in its data property all your values. A bit more js code, but a lot more flexibility.
Related
I am very confused by how to accomplish this, I have seen these: reference to similar question 1 & reference to similar question 2 None of these two question answers explains how I bind the actual datatable variable to the model since they are specified to the dropdownlist part more.
I have tried using two methods: One was to bind a list from a model to the datatable string and the other was to create a model class with a string that I bind by creating a list of the string object in the model in the controller. But my problem remains in that the datatable variables and the model item it is passed to dies inside the foreach.
So how should I use the model correctly to bind the datatable to the dropdownlist?
Controller:
BFProj2.Models.OurColumns o = new Models.OurColumns();
o.DCResults = new List<string>();
List<OurColumns> s = new List<OurColumns>();
for(int y = 0; y <csvData.Columns.Count; y++)
{
string dc = csvData.Columns[y].ColumnName.ToString();
//When the list is created in the model.
o.DCResults.Add(dc.ToString());
//when the list is created in the controller.
foreach(OurColumns dc1 in s)
{
dc1.result = dc;
}
}
//Still in try...
//
//
// Here the former binding to the database began.
//
//
}
catch (Exception ex)
{
//return View("Error"+ ex.GetType().ToString());
}
//csvData is {Table1}
}
return View();
}
csvData is the datatable.
Model:
namespace BFProj2.Models
{
public class OurColumns
{
//[DisplayName("Password")]
public string Password { get; set; }
//[DisplayName("Email")]
public string Email { get; set; }
//[DisplayName("Comment")]
public string Comment { get; set; }
//[DisplayName("Username")]
public string UserName { get; set; }
//[DisplayName("Firstname")]
public string FirstName { get; set; }
//[DisplayName("Lastname")]
public string LastName { get; set; }
//[DisplayName("Last activity date")]
public DateTime? LastUpdateDate { get; set; }
//[DisplayName("Title")]
public string Title { get; set; }
//[DisplayName("Abstract number")]
public int AbstrNum { get; set; }
//[DisplayName("Poster title")]
public string PosterTitle { get; set; }
//[DisplayName("Workshop")]
public string Workshop { get; set; }
//[DisplayName("Keywords")]
public string Keywords { get; set; }
//[DisplayName("Institution")]
public string Institution { get; set; }
//[DisplayName("Collaboration email")]
public string CollabEmail { get; set; }
public string SessionDate { get; set; }
//[DisplayName("DCResults")]
public List<string> DCResults { get; set; }
public string result { get; set; }
public List<string> SelectedDCResults { get; set; }
}
//public class SelectedDCResults
//{
// public string result { get; set; }
//}
}
View:
#model BFProj2.Models.OurColumns
#{
ViewBag.Title = "Importcsv";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Import CSV</h2>
#Html.EditorFor(model => model.FirstName)
<div class="display-field">
#Html.DropDownListFor(m => m.result, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.LastName)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.Email)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.UserName)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.Comment)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.Title)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.Workshop)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.AbstrNum)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.PosterTitle)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.Keywords)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.Institution)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
#Html.EditorFor(model => model.CollabEmail)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
<!--Add session date to UserInput table as string format-->
#Html.EditorFor(model => model.SessionDate)
<div class="display-field">
#Html.DropDownListFor(m => m.SelectedDCResults, new SelectList(Model.DCResults))
</div>
First, get this code out of your controller. In MVC controllers should be thin – their responsibility should be figuring out which View to render and passing data to and from the Views and the business layer.
Second, your View is strongly typed to the OurColumns object an instance of the OurColumns object is never passed the view. It looks like you need a ViewModel that has a collection of DCResults for your DropDownList and a string to capture the selected value. It is not strictly necessary to have a separate “Selected” item, but I like how it simplifies code – it’s a ViewModel after all.
public class ViewModel {
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public List<string> DCResults { get; set; }
public string SelectedDCResult { get; set; }
}
Your controller should be responsible for creating the View Model on the GET request and parse the ViewModel into the Business Object (or past that along to a service in a more layered application).
public ActionResult Get()
{
var model = new ViewModel {
DCResults = this.DcResultRepos.DCResults
};
return View(model);
}
public ActionResult Post(ViewModel model) {
if (ModelState.IsValid) {
//do something
}
return View("Another View");
}
If you are not using an ORM for persistent storage to object binding, then you will need to create your own, in another class so you can abstract away that binding from the WebUI. For the previous example, I used the following signature:
private class DCResultRepository {
public List<string> DCResults { get; }
}
In the body of the get (or helper method) you could process your DataTable and use yield return to create an IEnumerable that would allow you to use Linq in your controller. Like this:
private DataTable table;
public IEnumerable<Model> DCResults {
get {
//do something to get datatable
foreach(var row in table.Rows){
yield return new Model(){
//initialize values
};
}
}
}
I am using MVC in order to build a blog. What I want is to save post comments to its corresponding place in the database but it does not work.
My post model is as follows:
public class Post
{
[Key]
public int PostId { get; set; }
public string Title { get; set; }
public DateTime CreatedDate{get;set;}
public DateTime UpdateDate { get; set; }
public string Body { get; set; }
public ICollection<Comment> Comments { get; set;}
public ICollection<Tag> Tags { get; set; }
}
My Comment model is as follows:
public class Comment
{
[Key]
public int CommentId { get; set; }
public int PostId { get; set; }
[ForeignKey("PostId")]
public virtual Post Post{get; set;}
public string CommentCreateDate { get; set; }
public string CommentUpdateDate { get; set; }
public string CommeterName { get; set; }
public string EmailAddress { get; set; }
public string CommentText { get; set; }
public bool Approved { get; set; }
}
I have the following Action Methods:
[HttpGet]
public ActionResult CreateComment()
{
return View();
}
[HttpPost]
[ValidateInput(false)]
public ActionResult CreateComment(int id, string name, string email, string txt, bool aproved = false)
{
Post post = GetPost(id);
Comment comment = new Comment();
comment.Post = post;
comment.CommentCreateDate = DateTime.Now.ToString();
comment.CommeterName = name;
comment.EmailAddress = email;
comment.CommentText = txt;
comment.Approved = aproved;
db.Comments.Add(comment);
db.SaveChanges();
m_commentList.Add(comment);
return RedirectToAction("CreateComment", new { id = id });
}
And in my view I am trying this:
#model Blog.Models.Comment
#{
ViewBag.Title = "CreateComment";
}
<h2>Create a Comment</h2>
#using (Html.BeginForm())
{
<fieldset>
<legend>Enter Comment</legend>
<div class="editor-label">
#Html.LabelFor(model => model.CommeterName)
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.CommeterName)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.EmailAddress)
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.EmailAddress)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.CommentText)
</div>
<div class="editor-field">
#Html.TextAreaFor(model => model.CommentText)
</div>
<p>
<input type="submit" value="Create comment" />
</p>
</fieldset>
}
I get no exception but none of the data from the form is being saved. Only the data that is set in the action result, that is, CommentCreateDate and Approved. I am not sure what I am doing wrong.
I have tried a second option which is to include the id of the comment in BeginForm() as follows:
#using (Html.BeginForm(new {id = Model.CommentId}))
{
<fieldset>
<legend>Enter Comment</legend>
<div class="editor-label">
#Html.LabelFor(model => model.CommeterName)
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.CommeterName)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.EmailAddress)
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.EmailAddress)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.CommentText)
</div>
<div class="editor-field">
#Html.TextAreaFor(model => model.CommentText)
</div>
<p>
<input type="submit" value="Create comment" />
</p>
</fieldset>
}
This will give me a null reference exception even if I use the new keyword :
System.NullReferenceException: Object reference not set to an instance of an object.
Why is this happening? Can anybody help?
Thank you
Your action signature should be:
public ActionResult CreateComment(Comment model)
The names generated for the form fields will bind back to the properties of the same model class. There's no way for the framework to know, for example, that the CommenterName property should match up to the name parameter of the action.
Your second example makes very little sense - you're trying to write out the ID but you have never set one. In fact, you don't even pass a Comment to the view with the form, which is why you get a NullReferenceException:
[HttpGet]
public ActionResult CreateComment()
{
return View();
}
Also, you should be careful with what fields you expose to your models and actions. For example, a user could easily force their comment to be approved just by adding the following markup via their browser's development console:
<input type="hidden" name="approved" value="true" />
Anything that is either in your model properties or a parameter to your action can be set by the user.
An altogether better option would be to use a dedicated model class for the form:
public class CreateCommentViewModel
{
public string Name { get; set; }
public string Email { get; set; }
public string Text { get; set; }
}
Then to map this to your Comment in your action with:
[HttpPost]
public ActionResult CreateComment(CommentViewModel model)
{
var comment = new Comment();
comment.CommenterName = model.Name;
// etc...
}
This prevents the user from being able to set things like Approved and CreatedDate.
I will like to get the AddressAndPayment view being auto-populate from the UserProfile table.
I will like to use the fields from the UserProfile table to be auto-displayed in the AddressAndPayment.cshtml. I can't figure out how to perform this.
Some fields needs to come from Billing.cs and some other from the UserProfile Table.
Thanks.
The view I wanted to be populate is
AddressAndPayment.cshtml
#model Tp1WebStore3.Models.Billing
#{
ViewBag.Title = "AddressAndPayment";
}
<h2>Billing Info</h2>
#using (Html.BeginForm()) {
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<fieldset>
<legend>Billing</legend>
#Html.HiddenFor(model => model.BillingId)
<div class="editor-label">
#Html.LabelFor(model => model.LastNameBilling)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.LastNameBilling)
#Html.ValidationMessageFor(model => model.LastNameBilling)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.FirstNameBilling)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.FirstNameBilling)
#Html.ValidationMessageFor(model => model.PrenomFact)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.AdressBilling)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.AdressBilling)
#Html.ValidationMessageFor(model => model.AdressBilling)
</div>
Here are the field I store in the UserProfileTable from the AccountModels.cs
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Adress { get; set; }
}
Billing.cs
namespace Tp1WebStore3.Models
{
[Bind(Exclude = "BillingId")]
public partial class Billing
{
[ScaffoldColumn(false)]
public int BillingId { get; set; }
[ScaffoldColumn(false)]
public System.DateTime DateBilling { get; set; }
public string LastNameBilling { get; set; }
public string FirstNameBilling { get; set; }
public string AdresseBilling { get; set; }
CheckoutController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tp1WebStore3.Models;
namespace Tp1WebStore3.Controllers
{
[Authorize]
public class CheckoutController : Controller
{
Tp1WebStoreDBEntities storeDB = new Tp1WebStoreDBEntities();
//
// GET: /Checkout/AddressAndPayment
public ActionResult AddressAndPayment()
{
return View();
}
//
// POST: /Checkout/AddressAndPayment
[HttpPost]
public ActionResult AddressAndPayment(FormCollection values)
{
var billing = new Billing();
TryUpdateModel(billing);
try
{
billing.DateBilling = DateTime.Now;
//Process the order
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.CreateOrder(billing);
return RedirectToAction("Complete",
new { id = billing.BillingId });
}
catch
{
//Invalid - redisplay with errors
return View(billing);
}
}
//
// GET: /Checkout/Complete
public ActionResult Complete(int id)
{
return View(id);
}
}
}
Just add this to your AddressAndPayment GET action method:
//GET: /Checkout/AddressAndPayment
public ActionResult AddressAndPayment(int userId)
{
var user = storeDB.UserProfiles.FirstOrDefault(u => u.Id == Id);
var billing = new Billing();
billing.AdresseBilling = user.Adresse;
//etc... add anything else you need here
return View(billing);
}
Since it seems you are requiring that the user be logged in to get this far, then you could get the id from the current logged in user.
I have edit page and controller that creates new model object and fills some data from db into this object then send a model object to view. When I click the submit button, some fields in this object have been cleared.
For example:
Before:
user_id
name
birth_date
username
password
id_role
email
After (Fields that are not null or empty):
name
username
birth_date
The model:
public partial class Users
{
public Users()
{
this.Albums = new HashSet<Albums>();
this.History = new HashSet<History>();
this.Country = new HashSet<Country>();
this.Artists = new HashSet<Artists>();
this.SelectedCountries = new List<string>();
}
[DisplayName("User ID")]
public System.Guid user_id { get; set; }
[DisplayName("Name")]
public string name { get; set; }
[DisplayName("Birth date")]
public Nullable<System.DateTime> birth_date { get; set; }
[DisplayName("Username")]
public string username { get; set; }
[DisplayName("Password")]
public string password { get; set; }
[DisplayName("Rights")]
public System.Guid id_role { get; set; }
[DisplayName("User Email")]
public string email { get; set; }
public bool isRemember { get; set; }
public virtual ICollection<Albums> Albums { get; set; }
public virtual ICollection<History> History { get; set; }
public virtual Role Role { get; set; }
public virtual ICollection<Country> Country { get; set; }
public virtual ICollection<Artists> Artists { get; set; }
public virtual List<string> SelectedCountries { get; set; }
}
Edit method:
public ActionResult Edit()
{
if (HttpContext.User.Identity.IsAuthenticated)
{
var userName = HttpContext.User.Identity.Name;
var user = db.Users.Where(x => x.username == userName).FirstOrDefault();
ViewBag.Countries = new MultiSelectList(db.Country, "id_country", "name", user.SelectedCountries);
return View(user);
}
return HttpNotFound();
}
Edit method for handling post request:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Users users)
{
if (ModelState.IsValid)
{
foreach (var country in users.SelectedCountries)
{
var dbCountry = db.Country.Find(new Guid(country));
if (dbCountry != null)
users.Country.Add(dbCountry);
}
db.Entry(users).State = System.Data.Entity.EntityState.Modified;
//There handle of string array goes
db.SaveChanges();
return RedirectToAction("Index");
}
return View(users);
}
View:
<h2>Edit</h2>
#using (Html.BeginForm()) {
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<fieldset>
<legend>Users</legend>
<div class="editor-label">
#Html.LabelFor(model => model.name)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.name)
#Html.ValidationMessageFor(model => model.name)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.birth_date)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.birth_date)
#Html.ValidationMessageFor(model => model.birth_date)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.username)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.username)
#Html.ValidationMessageFor(model => model.username)
</div>
<div class="editor-label">
#Html.Label("Country")
</div>
<div class="editor-field">
#Html.DropDownList("SelectedCountries", (ViewBag.Countries as MultiSelectList), new { multiple = "multiple", #class = "chosen", style = "width: 350px;"})
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
Thanks in advance :)
You will only receive values that are in your form. Http is stateless..
What you need to do.. is create a ViewModel. That ViewModel is the subset of properties from your domain model that are displayed in the view. Like this:
public class UserViewModel {
public string Name { get; set; }
public string Username { get; set; }
public DateTime? DateofBirth { get; set; }
}
Use this model in your view. Then, in your controller.. get the user and update the appropriate fields:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(UserViewModel viewModel) {
var user = db.Users.Where(x => x.username == viewModel.Username).FirstOrDefault();
user.Name = viewModel.Name;
user.Username = viewModel.Username;
// .. etc.
db.SaveChanges();
}
If you are worried about all of the manual mapping involved in this, there exists frameworks to help you with that:
Automapper
ValueInjector
You are heading down a very very daunting path if you start adding hidden fields into your view. Its a maintenance nightmare and very error prone.
The post operation only collects the values you have in the form.
If you want the other values to proceed in your controllers post-method, you can for example, add hidden fields.
#Html.HiddenFor(x => x.HiddenPostBack)
this is my partial:
#model RazorSharpBlog.Models.MarkdownTextAreaModel
<div class="wmd-panel">
<div id="wmd-button-bar-#Model.Name"></div>
#Html.TextAreaFor(m => m.Name, new { #id = "wmd-input-" + #Model.Name, #class = "wmd-input" })
</div>
<div class="wmd-panel-separator"></div>
<div id="wmd-preview-#Model.Name" class="wmd-panel wmd-preview"></div>
<div class="wmd-panel-separator"></div>
I'm trying to include it like this in my View:
#using (Html.BeginForm())
{
#Html.LabelFor(m => m.Title)
#Html.TextBoxFor(m => m.Title)
#Html.Partial("MarkdownTextArea", new { Name = "content" })
<input type="submit" value="Post" />
}
these are the model classes:
public class MarkdownTextAreaModel
{
[Required]
public string Name { get; set; }
}
public class BlogContentModel
{
[Required]
[Display(Name = "Post Title")]
public string Title { get; set; }
[Required]
[DataType(DataType.MultilineText)]
[Display(Name = "Post Content")]
public string Content { get; set; }
}
What am I doing wrong, how should I do this in order to make my partial reusable?
Your partial expects an instance of the MarkdownTextAreaModel class. So do so, instead of passing an anonymous object which would throw anyways:
#Html.Partial("MarkdownTextArea", new MarkdownTextAreaModel { Name = "content" })
Now this being said a far better solution would be to adapt your view model, so that it contains a reference to MarkdownTextAreaModel and use editor templates instead of partials in your views, just like so:
public class BlogContentModel
{
[Required]
[Display(Name = "Post Title")]
public string Title { get; set; }
[Required]
[DataType(DataType.MultilineText)]
[Display(Name = "Post Content")]
public string Content { get; set; }
public MarkdownTextAreaModel MarkDown { get; set; }
}
then of course readapt the controller serving this view so that it populates the MarkDown of your view model:
public ActionResult Foo()
{
BlogContentModel model = .... fetch this model from somewhere (a repository?)
model.MarkDown = new MarkdownTextAreaModel
{
Name = "contect"
};
return View(model);
}
and then inside your main view simply:
#using (Html.BeginForm())
{
#Html.LabelFor(m => m.Title)
#Html.TextBoxFor(m => m.Title)
#Html.EditorFor(x => x.MarkDown)
<input type="submit" value="Post" />
}
and then in order to follow standard conventions move your partial to ~/Views/YourControllerName/EditorTemplates/MarkdownTextAreaModel.cshtml and now everything will magically come into place as it should.
#using (Html.BeginForm()) {
#Html.LabelFor(m => m.Title) #Html.TextBoxFor(m => m.Title)
#Html.Partial("MarkdownTextArea", new MarkdownTextAreaModel { Name = "content" })
<input type="submit" value="Post" />
}