using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mime;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using CompanyShop.Web.Models;
using Umbraco.Core;
using Umbraco.Web.Mvc;
namespace CompanyShop.Web.Controllers
{
public class AgentLoginController : SurfaceController
{
[HttpGet]
[ActionName("AgentLogin")]
public ActionResult AgentLoginGet()
{
return PartialView("_AgentLogin", new AgentLoginModel());
}
[HttpPost]
[ActionName("AgentLogin")]
public ActionResult AgentLoginPost(AgentLoginModel model)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return RedirectToCurrentUmbracoPage();
}
TempData["Status"] = "Invalid username or password";
return RedirectToCurrentUmbracoPage();
}
[HttpGet]
public ActionResult AgentLogout()
{
Session.Clear();
FormsAuthentication.SignOut();
return Redirect("/");
}
}
How to call partial view in macro and display in content ?
Hi Guys,
I am using Umbraco 7.1.6 version for my project.
I have created one page called login.cshtml in Views -> Partials.
I would like it to be available in the content rich text editor.
I have tried to create macro and gave login.cshtml file name in Razor script. but it is not working.
can anyone help me to create a macro with .cshtml file and call it in content page ?
Thanks, Priya
Hi,
It is simple one.
in your macro file you just have one line of code
In your Surface controller
Hope this will help
Yasir
Hi Yasir,
Thank you very much for you reply.
I am new with this umbraco development.
I have created following code under settings -> partial views
@model CompanyShop.Web.Models.AgentLoginModel @if (User.Identity.IsAuthenticated) {
Logged in: @User.Identity.Name
@Html.ActionLink("Log out", "AgentLogout", "AgentLogin")
Register new customer} else { using (Html.BeginUmbracoForm("AgentLogin", "AgentLogin"))
{
}
Now in macro file where to write @Html.Action("Index","LoginSurface") code ?
In macro I have got following : Name : Alias :
Choose a file to render :
MVC partial view: xslt: user control: Razor contro:
Editor settings : Use in rich text box render in rich text editor : catch settings can you please help me where to write that code ?
Thanks, Priya
Hi Priya
It should write in MVC partial view.
Yasir
Hi Yasir,
Thanks for the reply
I have got following code in surface controller.
using System; using System.Collections.Generic; using System.Linq; using System.Net.Mime; using System.Web; using System.Web.Mvc; using System.Web.Security; using CompanyShop.Web.Models; using Umbraco.Core; using Umbraco.Web.Mvc;
namespace CompanyShop.Web.Controllers { public class AgentLoginController : SurfaceController { [HttpGet] [ActionName("AgentLogin")] public ActionResult AgentLoginGet() { return PartialView("_AgentLogin", new AgentLoginModel()); }
}
Do I need to add anything else here ?
Thanks, Priya
No i dont think so.
It looks good. Are you getting any error?
Yasir
Hi Yasir,
when I tried to call that macro in content rich text editor it giving me following error:
Error loading partial view script(file:~views/macropartials/comlogin.cshtml)
I am not able to understand what is the problem ?
Priya
I wrote following in partial view macro file.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Action("Index","AgentLoginController")
does this right ?
Priya
I assumed that your partial is under sub folder some where.
if it is the case then you should pass the full path in PartialView for example.
if it is not the case then you should add the break point on your AgentLoginGet action method and see what causing the error
Yasir
Hi yasir,
I did change the path. I think I wrote something wrong in macro partial file. can you please tell what exactly I have to write in macro partial ?
I wrote like :
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@Html.Action("AgentLogin","AgentLoginModel")
Priya
Hi,
It should be
@Html.Action("ActionMethod", "Controller")
in your case
Yasir
Hi yasir,
I have changed it but still getting same error.
I have tried to add bread point also but I didn't find anything :(
Can you check this code as well may be something wrong in this
@model CompanyShop.Web.Models.AgentLoginModel @if (User.Identity.IsAuthenticated) {
Logged in: @User.Identity.Name
@Html.ActionLink("Log out", "AgentLogout", "AgentLogin")
Register new customer} else { using (Html.BeginUmbracoForm("AgentLogin", "AgentLogin"))
{
}
Thanks,
Priya
Error is in your form code which your pasted
you cant write the text directly inside the razor. you have to write the text in variable or other ways then print it
i changed it like below but you can change it
I did try to change this code but still same error.
don't know what wrong now ?
:(
Priya
Try this one in your view. if any name is not matched with your controller or action please change it according to yours
}
is working on a reply...