Does a child action share the same ViewBag with its “parents” action?

Child actions follow a different controller/model/view lifecycle than parent actions. As a result they do not share ViewData/ViewBag. If you want to pass parameters to a child action from the parent you could do this: @Html.Action(“Child”, new { message = ViewBag.Message }) and in the child action: public ActionResult Child(string message) { … }

How do I get the full name of a user in .net MVC 3 intranet app?

You can do something like this: using (var context = new PrincipalContext(ContextType.Domain)) { var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name); var firstName = principal.GivenName; var lastName = principal.Surname; } You’ll need to add a reference to the System.DirectoryServices.AccountManagement assembly. You can add a Razor helper like so: @helper AccountName() { using (var context = new PrincipalContext(ContextType.Domain)) { … Read more

How Can I Have View-Specific contents Using Asp.Net MVC 3 and Razor?

The equivalent of content placeholders in Razor are sections. In your _Layout.cshtml: <head> @RenderSection(“Styles”, required: false) </head> Then in your content page: @section Styles { <link href=”https://stackoverflow.com/questions/4739907/@Url.Content(“~/Content/StandardSize.css”)” /> } An alternative solution would be to put your styles into ViewBag/ViewData: In your _Layout.cshtml: <head> @foreach(string style in ViewBag.Styles ?? new string[0]) { <link href=”https://stackoverflow.com/questions/4739907/@Url.Content(style)” /> … Read more

.Net Mvc 3 Trigger (other than submit button) Unobtrusive Validation

$(‘form’).valid() should work. Let’s exemplify. Model: public class MyViewModel { [Required] public string Foo { get; set; } } Controller: public class HomeController : Controller { public ActionResult Index() { return View(new MyViewModel()); } } View: @model MyViewModel <script src=”https://stackoverflow.com/questions/6301492/@Url.Content(“~/Scripts/jquery.validate.js”)” type=”text/javascript”></script> <script src=”https://stackoverflow.com/questions/6301492/@Url.Content(“~/Scripts/jquery.validate.unobtrusive.js”)” type=”text/javascript”></script> @using (Html.BeginForm()) { @Html.LabelFor(x => x.Foo) @Html.EditorFor(x => x.Foo) @Html.ValidationMessageFor(x => … Read more

What colon ( : ) means defining a class in c#?

In this case it means that the HomeController inherits the Controller class. You can read more details about inheritance here, but simply put – inheritance means that everything a Controller is, a HomeController is also. A HomeController is a more finely grained Controller class. It can also be used for implementation of interfaces http://msdn.microsoft.com/en-us/library/ms173156.aspx

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