I always feel that asp.net MVC is awkward to write. Compared with PHP's mvc, asp.net is a lot more troublesome?
漂亮男人
漂亮男人 2017-05-16 17:06:17
0
3
690

Does anyone feel the same way?

How to write mvc?

I find it very difficult to write

PHP:

M:
class Teacher {
  function add($data) {
    $sql = "insert into teacher_table($teacher_name) values($data['teacher_name'])";
    return $db->query($sql);
  }
}

V:
(省略)

C:
class Teacher {
  $data = array("teacher_name"=>$_POST["teacher_name"],....);
  $row = new Teacher();
  $row->add($data);
  echo "Yeah~!";
}

asp.net does not have an array as flexible as PHP. Data exchanges between m-v-c are all passed through arrays. Asp.net can't have a hashtable, right? It seems that the tutorials all write entity classes

漂亮男人
漂亮男人

reply all(3)
刘奇

I have never written PHP, but I have experience in ASP.NET MVC development. Here I will briefly explain my understanding.
First, let’s look at an interaction principle of ASP.NET MVC through a picture:

The Model layer is actually a big concept, including services, business logic, data persistence, etc.; the Controller layer plays a role in connecting the Model layer and the View layer; the View layer is the interface, which should be very important. clear.
From your description of the problem, the more tangled point is that when the Controller layer and the View layer interact, ASP.NET MVC uses the method of defining entity classes (ViewModel), which makes you feel that the development method of ASP.NET MVC is very complicated. Effortless.
In fact, this question is relative. First of all, for ASP.NET MVC, basically every view must define a ViewModel. This is indeed a very boring place, but in retrospect it brings benefits: Cooperating with Visual Studio, you can use smart prompts in the view (I won’t expand on smart prompts here, everyone who has used them says it’s good)! In this way, you can avoid the magic string problem in the PHP array $data['xxx'] (for example, you should write $data['teacher'], but accidentally write the wrong $data['teach'], which brings more It's possible to make mistakes, don't you think writing these strings is also a boring thing?).
If you think the array method is better, you can actually do it in ASP.NET MVC. You can use TempData in the Controller class, for example:

public ActionResult List()
{
    TempData["hello"] = "world";
    return View();
}

In this way, the view layer can also obtain data through TempData[].

洪涛

In .Net, your $data can be described by the type Dictionary<string, string> or Dictionary<string, object>.
It's not convenient at all. There are no auto-complete prompts and no static checks in the IDE.

世界只因有你

I have been using it for a long timeasp.net mvc,现在用phpyii,两者几乎完全一样的思想。所以不是说框架哪个更方便,而是语言哪个更方便。我个人也觉得php确实比C#要方便很多,就像你说的,数组灵活,json灵活,.net现在也有dynamic类型,但是不感冒,感觉生硬。另外一个抛弃微软的理由就是觉得太麻烦,太封闭,就是不愿意用windows,干嘛要用宇宙第一IDE(visual studio)?老子就是只愿意在linux下用vim, nothing else.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template