I have some interesting observations today, I need to explain why I get my person
class Is as described above:
public class person {public Ent ID (Received); Set; } Public string first name {receives; Set; } Public String LastName {get; Set; }}
Now in my MVC2 application I found PersonController with the following edit in Metro:
Edit public function (int id) {var permission = _service .GetPerson (ID); View return (person); } [Http post] edit public functioning (person person) {if (ModelState.IsValid) {_service.UpdatePerson (permission); Redirect action ("index"); } View return (person); }
Now in my Edit.aspx
view I have a form with only first name and last name, but what happens to me when posted in my controller It is surprising that an ID is defined in the person
object (which was not part of any form).
Now I think this ID has been taken from the root value of the parameter, which is known to my action, but is it left? I mean .. It is good that I do not have to hide the hidden field for the ID, but is there a danger due to mixing together with the parameters of MVC 2?
And one more worry, if I have hidden it for ID, then it will be sent in both ways (received and posted), then .. which ID will be used?
Yes, it has been taken along the route. This is dangerous because if you change the name of the person in this category then your code may break, except that if you change the route then this can also happen.
And to answer your second question. Assume the following form:
& lt; Form action = "/ home / edit / 5" method = "post" & gt; & Lt; Input type = "text" name = "id" value = "1" /> & Lt; Input type = "submit" value = "go" /> & Lt; / Form & gt;
In this case the ID will be taken from the POST request and not the route.
Comments
Post a Comment