I love MVC, coming from WebForms development, but there are things that don't make any sense to me. The "Error executing child handler" occurs anytime a vast number of things happen, for instance. It's very close to a useless message. In order to get the actual cause, I click on Debug/Exceptions and check the "Common Language Runtime Exceptions", and then reload the View. Presto! It shows the cause of the error.
Another thing I'm wondering about today is the FormCollection value of the Html.CheckBoxFor control. Checkboxes in general seem badly designed in html, and MVC didn't improve on it much. When processing a POST, if a regular checkbox isn't checked, it simply won't show up in the list of posted elements. Great. Instead of just grabbing it by name in the FormCollection and testing its value, instead I have to test whether or not it exists in the FormCollection. Not very intuitive. The Html.CheckBoxFor is a variant on the same theme. It always shows up in the FormCollection, but with a similarly non-intuitive return. If it's not checked, it yields a value of 'false', which can simply be converted to boolean and processed as normal. But if it is checked, it returns 'true,false'. Super. Now, instead of converting its value to a boolean directly, I have to test the string returned for the index of 'true' and return that instead.
I find this close to as aggravating as the Linq To Sql Sum() method bug. If I run a Select() method on a given numeric property and run Sum() to add them all together, if an empty result set is returned by the query it throws an exception. Now, if I was looking at a bunch of totals to add together, and none of them had anything entered, what would I write in the sum box? Error? Exception? Nope, it would be zero. I fully understand that if no results were returned then nulls cannot be added, but according to the intitial documentation this method was supposed to return zero in such an instance regardless, because that's just common sense. Enough of that rant. Does anyone know why this return value was chosen for Html.CheckBoxFor?
I have looked all over for elegant solutions to this not so age-old question. How can I lock down form elements within an ASP.Net MVC View, without adding if...then logic all over the place? Ideally the BaseController, either from OnAuthorization, or OnResultExecultion, would check the rendering form elements and hide/not render them based on role and scope. Another approach I have considered is writing some sort of custom attributes, so as to stay consistent with how how we lock down ActionResults with [Authorize]. Is this even possible without passing a list of hidden objects to the view and putting if's all over? Other background info: We will have a database that will tell us at execution time (based on user role/scope) what elements will be hidden. We are using MVC3 with Razor Viewengine. We're utilizing a BaseController where any of the Controller methods can be overridden.
If I look at the Razor View Engine, then I see a very nice and concise syntax that is not particularly tied to generating html. So I wonder, how easy would it be to use the engine outside asp.net in a "normal" .net environment for example to generate text, code,...
I have an application which has been built in MVC 2.0. I need to upgrade it to MVC 3.0 and that too by using Razor CSHTML engine. All the information which I got on the net was for MVC 3.0 Webform engine but nothing much for migrating to Razor.
I can't seem to figure out how to set a breakpoint in a Razor view. I understand why that might seem a little weird and may be difficult since a cshtml file is a combination of html and then c# code, but I can step into it. The ability to step into it makes it seem like I should be able to set a breakpoint. Am I missing how to do this or is this not possible in the RC? If not any plans to add this before RTM or in the future?
How can I render a razor view in a Unit Test?When I change for instance a html helper method, I sometimes forget to update all the views which uses that html method. So the view I forgot generates a YSOD.I would like to create unit tests that renders a view and fails if I forgot to make the neccecary updates.
In my controller method, I'm trying to create an instance of a View (cshtml file) before I wrap it around an ActionResult and return it.Since there is no "class" for Razor Views to speak off, how does one go about creating an instance of a Razor View?
I am currently writing a small templating system in ASP.NET to allow users to add content. For example, the user can enter the string (variable type is string).
topHeader[x] = "They think it's all over. It is now!";
However, one change that's needed is the ability to add some basic HTML tags within this content, so the following can be done
topHeader[x] = "They think it's all over. <strong>It is now!</strong>" or
topHeader[x] = "They think it's all over. <a title="Football News" href="URL">It is now!</a>";
If you add such things into strings now they are not formatted as HTML, but I want to somehow escape them so that they can be. Naturally I've looked on the Internet for the answer, but as Razor is fairly new there's not much out there to help me out.