I have a custom model file, authentication cookie validation and return value.
public class UserDataModelBinder<T> : IModelBinder { public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (controllerContext.RequestContext.HttpContext.Request.IsAuthenticated) { var cookie = controllerContext.RequestContext.HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie == null) return null; var decrypted = FormsAuthentication.Decrypt(cookie.Value); if (!string.IsNullOrWhiteSpace(decrypted.UserData)) return JsonSerializer.DeserializeFromString<T>(decrypted.UserData); } return null; } }
if I need to use it, I just need to transfer it to action. everything works.
public ActionResult Index(UserData userData) { AccountLoginWidgetVM model = new AccountLoginWidgetVM(); if (null != userData) model.UserData = userData; return View(userData); }
However, I want to use it on my main page, because after logging in, I want to display their information on the top of each page. I tried a few things without getting it.
@Html.RenderPartial("LoginPartial", ???model here??)
source share