How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file?

You could put a _ViewStart.cshtml file inside the /Views/Public folder which would override the default one in the /Views folder and specify the desired layout: @{ Layout = “~/Views/Shared/_PublicLayout.cshtml”; } By analogy you could put another _ViewStart.cshtml file inside the /Views/Staff folder with: @{ Layout = “~/Views/Shared/_StaffLayout.cshtml”; } You could also specify which layout should … Read more

HTML.ActionLink vs Url.Action in ASP.NET Razor

Yes, there is a difference. Html.ActionLink generates an <a href=”https://stackoverflow.com/questions/7709001/..”></a> tag whereas Url.Action returns only an url. For example: @Html.ActionLink(“link text”, “someaction”, “somecontroller”, new { id = “123” }, null) generates: <a href=”https://stackoverflow.com/somecontroller/someaction/123″>link text</a> and Url.Action(“someaction”, “somecontroller”, new { id = “123” }) generates: /somecontroller/someaction/123 There is also Html.Action which executes a child controller action.

What’s the difference between ViewData and ViewBag?

It uses the C# 4.0 dynamic feature. It achieves the same goal as viewdata and should be avoided in favor of using strongly typed view models (the same way as viewdata should be avoided). So basically it replaces magic strings: ViewData[“Foo”] with magic properties: ViewBag.Foo for which you have no compile time safety. I continue … Read more

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

Sections don’t work in partial views and that’s by design. You may use some custom helpers to achieve similar behavior, but honestly it’s the view’s responsibility to include the necessary scripts, not the partial’s responsibility. I would recommend using the @scripts section of the main view to do that and not have the partials worry … Read more

How to set value of input text using jQuery

Your selector is retrieving the text box’s surrounding <div class=”textBoxEmployeeNumber”> instead of the input inside it. // Access the input inside the div with this selector: $(function () { $(‘.textBoxEmployeeNumber input’).val(“fgg”); }); Update after seeing output HTML If the ASP.NET code reliably outputs the HTML <input> with an id attribute id=’EmployeeId’, you can more simply … Read more

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> }