How to declare a local variable in Razor?

I think you were pretty close, try this: @{bool isUserConnected = string.IsNullOrEmpty(Model.CreatorFullName);} @if (isUserConnected) { // meaning that the viewing user has not been saved so continue <div> <div> click to join us </div> <a id=”login” href=”https://stackoverflow.com/questions/6601715/javascript:void(0);” style=”display: inline; “>join here</a> </div> }

ASP.NET Identity – HttpContext has no extension method for GetOwinContext

ARGH! I found it… I didn’t have an extra package, called Microsoft.Owin.Host.SystemWeb Once i searched and installed this, it worked. Now – i am not sure if i just missed everything, though found NO reference to such a library or package when going through various tutorials. It also didn’t get installed when i installed all … Read more

Reflecting parameter name: abuse of C# lambda expressions or syntax brilliance? [closed]

I find that odd not so much because of the name, but because the lambda is unnecessary; it could use an anonymous-type and be more flexible: .Attributes(new { style = “width:100%”, @class=”foo”, blip=123 }); This is a pattern used in much of ASP.NET MVC (for example), and has other uses (a caveat, note also Ayende’s … Read more

ASP.NET MVC controller actions that return JSON or partial html

In your action method, return Json(object) to return JSON to your page. public ActionResult SomeActionMethod() { return Json(new {foo=”bar”, baz=”Blech”}); } Then just call the action method using Ajax. You could use one of the helper methods from the ViewPage such as <%= Ajax.ActionLink(“SomeActionMethod”, new AjaxOptions {OnSuccess=”somemethod”}) %> SomeMethod would be a javascript method that … Read more

How can I properly handle 404 in ASP.NET MVC?

The code is taken from http://blogs.microsoft.co.il/blogs/shay/archive/2009/03/06/real-world-error-hadnling-in-asp-net-mvc-rc2.aspx and works in ASP.net MVC 1.0 as well Here’s how I handle http exceptions: protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); // Log the exception. ILogger logger = Container.Resolve<ILogger>(); logger.Error(exception); Response.Clear(); HttpException httpException = exception as HttpException; RouteData routeData = new RouteData(); routeData.Values.Add(“controller”, “Error”); if … Read more

Using Razor within JavaScript

Use the <text> pseudo-element, as described here, to force the Razor compiler back into content mode: <script type=”text/javascript”> // Some JavaScript code here to display map, etc. // Now add markers @foreach (var item in Model) { <text> var markerlatLng = new google.maps.LatLng(@(Model.Latitude), @(Model.Longitude)); var title=”@(Model.Title)”; var description = ‘@(Model.Description)’; var contentString = ‘<h3>’ + … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)