In the problem prepopulate Html.TextBoxFor in asp.net mvc 3 you can see an answer in which the following piece of code works correctly.
ViewBag.CompName = "Some Name";
Then in your view:
@Html.TextBoxFor(model =>model.Comps.CompName, new {@Value = ViewBag.CompName})
However, when the textbox gets the initial value of an empty string "", it seems to post a value of null for this textbox.
ViewBag.CompName = "";
This sends a null value instead of an empty string.
Is there any way of returning an empty string instead of null?
ViewBag, you can addstring.emptyinstead ofViewBag.CompNameif it is null