W
W
wkololo_4ever2014-02-02 13:52:48
HTML
wkololo_4ever, 2014-02-02 13:52:48

Simple ASP.NET MVC Form Data Submission?

I'm trying to pass data from one form to another without helper methods.
Model

public class something
    {
        public string SomethingField;
    }

Controller
public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ViewResult Form(something someObj)
        {
            return View("Form",someObj);

        }

    }

Two Views:
1) Index.cshtml
@{
    ViewBag.Title = "View1";
}

<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
</head>
<body>
    <form action="/Home/Form" method="post">
        <input type="text" name="SomethingField" />
        <input type="submit" value="Отправить" />
    </form>
</body>
</html>

2)Form.cshtml
@model MvcApplication2.Models.something

@{
    ViewBag.Title = "Form";
}

<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
</head>
<body>
    @Model.SomethingField  
</body>
</html>

When filling in the "SomethingField" field in the form and clicking the button, nothing is displayed, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wkololo_4ever, 2014-02-02
@wkololo_4ever

It turns out you need to use properties, not fields, for the default convention to work.

N
Nikolai Turnaviotov, 2014-02-03
@foxmuldercp

Read the lessons on creating a disc store and a movie catalog for mvc3/4 from the site, a lot will become clear to you. but there are only the basics, there are no helpers ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question