0

Hi all, I'm just redoing a very simple MVC app found on a book and I have created my model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcGuestbookRevised.Models
{
    public class GuestbookEntry
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Message { get; set; }
        public DateTime DateAdded { get; set; }
    }
}

then using Entity Framework, I created a controller called GuestbookEntryController with read/write actions and views. It's all OK but when I navigated to the create URL localhost:xxxx/GuestbookEntry/Create I have my input fields, but I wanted that "Message" to be a textarea and not an input field. How do I do that? I don't seem to be able to change it in the Create view as I thought I'd do because there is nothing to change in there, here it is:

@model MvcGuestbookRevised.Models.GuestbookEntry

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>GuestbookEntry</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.Message)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Message)
            @Html.ValidationMessageFor(model => model.Message)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateAdded)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateAdded)
            @Html.ValidationMessageFor(model => model.DateAdded)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Any idea? Or was the approach to use an Entity Framework controller wrong in the first place?
thanks

2
Contributors
4
Replies
21
Views
2 Years
Discussion Span
Last Post by Violet_82
0

You can add [DataType(DataType.MultilineText)] just before your property definition, or use:

@Html.TextAreaFor(model => model.Message, new { cols = 35, @rows = 3 })

Edited by pritaeas

0

Oh I see, thank you. Is there a resource anywhere which lists all those (are they called HTML Helpers?) so I know what renders what?
thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.