开发者

If Action link is disabled, how to make it not accessible through url in MVC3

开发者 https://www.devze.com 2023-03-29 06:44 出处:网络
In my view I disable or enable links as below. Even if the link \"Insured or Owner Name Change\" is disabled in the view I am able to access it through the url like \"http://localhost:0000/NameChangeR

In my view I disable or enable links as below. Even if the link "Insured or Owner Name Change" is disabled in the view I am able to access it through the url like "http://localhost:0000/NameChangeRequest?contract=111111" which should not be happening. Can anyone help me on this?

           @if (Model.CanCreateNameChangeRequest)
                    {
                        @Html.ActionLink("Insured or Owner Name Change", "Index", "NameChangeRequest", new { @contract = Model.ContractNumber }, new { @class = "requestLink" });
                    }
                    else
                    {
                        <span class="requestLinkDisabled">开发者_如何学GoInsured or Owner Name Change</span>
                    }


You should never use Views to handle access control or any nature of business logic really. The View should only have presentation layer logic and markup.

That said, you can do this in the "NameChangeRequestController" -> "Index" action:

public ActionResult Index()
{
    if(!Model.CanCreateNameChangeRequest)
        RedirectToAction("Index","Home");
}

Also, this looks a lot like Role based permissions, in which case you should use the "[Authorize]" attribute along with "IsInRole".

0

精彩评论

暂无评论...
验证码 换一张
取 消