Есть код
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Movie newMovie)
{
if (ModelState.IsValid)
{
db.AddToMovies(newMovie);
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(newMovie);
}
}
Почему нет создания экземпляра класса, как например здесь:
1)
https://professorweb.ru/my/ASP_NET/mvc/level7/7_1.php Привязка сложных типов
using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Mvc;
using MvcModels.Models;
namespace MvcModels.Controllers
{
public class HomeController : Controller
{
// ...
public ActionResult CreateUser()
{
return View(new User());
}
[HttpPost]
public ActionResult CreateUser(User model)
{
return View("Index", model);
}
}
}
2) как в php(yii2) например
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\EntryForm;
class SiteController extends Controller
{
// ...existing code...
public function actionEntry()
{
$model = new EntryForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
// valid data received in $model
// do something meaningful here about $model ...
return $this->render('entry-confirm', ['model' => $model]);
} else {
// either the page is initially displayed or there is some validation error
return $this->render('entry', ['model' => $model]);
}
}
}