Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:20:04+00:00 2026-06-08T05:20:04+00:00

I have a View with a <input type=submit value=Create /> when a User click

  • 0

I have a View with a <input type="submit" value="Create" /> when a User click create the Action Method should be activated and the Result written in the db.

At the moment when a User click Create Button in the View nothing happen. Could you tell me what I’m doing wrong? thanks

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestGuestBook.Models;
using TestGuestBook.Models.Repositories;
using TestGuestBook.ViewModels;

namespace TestGuestBook.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {

        ICommentRepository _repository;

        public HomeController()
        {
            _repository = new CommentRepository();
        }

        // Dependency Injection enabled constructors
        public HomeController(ICommentRepository repository)
        {
            _repository = repository;
        }

        public ActionResult Index()
        {
            // Get all Comments
            List<Comment> commentItems = _repository.FindAll().ToList();
            // Create the ViewModel and associate the list of comments
            CommentListCreateViewModel viewModel = new CommentListCreateViewModel();
            viewModel.CommentItems = commentItems;

            return View(viewModel);
        }

        public ActionResult Create()
        {
            CommentListCreateViewModel createViewModel = new CommentListCreateViewModel();
            return View(createViewModel);
        }

        [HttpPost]
        public ActionResult Create(CommentListCreateViewModel createViewModel)
        {
            if (ModelState.IsValid)
            {
                Comment comment = new Comment
                {
                    Nominative = createViewModel.Nominative,
                    Email = createViewModel.Email,
                    Content = createViewModel.Content
                };
                _repository.Add(comment);
                _repository.Save();
            }
            return View();
        }

    }
}

View

@model TestGuestBook.ViewModels.CommentListCreateViewModel
@{
    ViewBag.Title = "Index";
}
<h2>
    Index</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>ListAddCommentsViewModel</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.Nominative)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nominative)
            @Html.ValidationMessageFor(model => model.Nominative)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Content)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Content)
            @Html.ValidationMessageFor(model => model.Content)
        </div>
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<table>
    <tr>
        <th>
            Nominative
        </th>
        <th>
            Email
        </th>
        <th>
            Content
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model.CommentItems)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Nominative)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Email)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Content)
            </td>
            <td>
            </td>
        </tr>

    }
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:20:09+00:00Added an answer on June 8, 2026 at 5:20 am

    You need to direct the form to your Create controller method:

    @using (Html.BeginForm("Create", "Home"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How submit list View in ASP.NET MVC. List View dont have input type=submit value=Save
I have a view that dynamically updates depending on user input - here's how
Hi all I have a view with these controls on it <input type=text class=radius2
I have created a View which prompts the user to input some records with
I have a NSURL member in my view controller. Based on user input like
I have a View where some input text to be added dynamica using jquery,
I have an iPhone app which has a Table View-based data input screen with
I have two form fields on my view page, a date input (with a
i have view like 'home/details/5', it can be access by anonymous user. but there
I have the following form in a partial view @model PartDetail @using (Ajax.BeginForm(Create, Part,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.