标签: actionlink

在ajax回调之后的$(document).ready在ascx页面中

我在这里设置有一点问题我有一个.ascx文件列表,他们都在计算控制器本身方面做了不同的任务.因此,在我的.aspx页面上,我单击一个Ajax.ActionLink(),这将.ascx根据我单击的项目呈现该特定文件.其中.ascx有1-3个事件将触发其中2个onclick事件,1个事件onload.该onclick事件(S)更容易在我而言一起工作可以直接在控制事件硬编码像这样onclick="$("#toggleMe3").slideToggle("slow");"onload必须运行时.ascx加载我是在测试这个$(document).ready(function(){});电话,这部作品在精细.aspx页,但只要我尝试将它添加到.aspx它没有加载的页面中,这是理想的,但是我不知道为什么不这样做.实际上,如果我直接插入到.ascx页面中,那么脚本标签中没有任何内容可用,如果硬编码到控件的事件中,它们至少会有一些; 在onloadonprerender不火.

ajax asp.net-mvc jquery user-controls actionlink

5
推荐指数
1
解决办法
9171
查看次数

mvc ajax.actionlink与jquery对话框确认

我有一个包含一些数据项行的表.对于每一行,它将是一些将调用某些方法的actionlinks(删除dataitem,更改状态dataitem等...)

在每个用户单击按钮之前,我想要显示一个jquery对话框,并为用户提供一个包含一些信息的对话框,一个OK和Cancel按钮.

将调用ChangeStatus方法的ajax.actionlink的一些示例代码:

<%= Ajax.ActionLink(item.Status, "ChangeStatus", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "ListReturns-Div", OnBegin = "StartChangeStatus", OnSuccess = "EndChangeStatus", OnFailure = "FailureChangeStatus" }, new { @class = "StatusBtn" })%>
Run Code Online (Sandbox Code Playgroud)

这是调用的jquery函数:

 function StartChangeStatus(e) {
            $('#dialog-confirm').dialog({
                resizable: false,
                height: 200,
                modal: true,
                buttons: {
                    'Continue': function () {
                        $(this).dialog('close');
                        $('#Loading-Div').show('slow');
                    },
                    Cancel: function () {
                        $(this).dialog('close');
                        e.preventDefault();
                    }
                }
            });
        }
Run Code Online (Sandbox Code Playgroud)

actionlink和jquery函数有效.但问题是,当单击actionlink时,我无法暂停/停止当前操作.单击该按钮时,现在正在运行孔过程,并忽略对话框确认按钮.所以我的问题是如何在继续之前更改actionlink或jquery函数以使用对话框确认按需工作?

asp.net-mvc jquery actionlink jquery-ui-dialog

5
推荐指数
1
解决办法
9568
查看次数

带有LinkText的ASP.NET MVC ActionLink =绝对URL

<%: Html.ActionLink("Share Me", "Index", "Mall", new { username = Model.Username }, null)%>
Run Code Online (Sandbox Code Playgroud)

根据映射的路线预期结果:

<a href="/Mall/Username">Share Me</a>
Run Code Online (Sandbox Code Playgroud)

我需要它不要说Share Me但是要显示绝对URL,以及使用绝对URL作为href:

<a href="http://www.url.com/Mall/Username">http://www.url.com/Mall/Username</a>
Run Code Online (Sandbox Code Playgroud)

我觉得这不是一项艰巨的任务,但在处理MVC方面非常环保,我很难搞清楚它.

actionlink asp.net-mvc-2

5
推荐指数
1
解决办法
3144
查看次数

如何覆盖ActionLink行为

好的,我想通过ActionLink方法为我的网站添加一些安全性.如果用户有足够的权限访问操作/控制器,则ActionLink应呈现链接.如果没有,它应该返回一个空字符串.现在,ActionLink是一种静态方法,这使得它变得更加困难.有没有办法实现我想要做的事情?

overriding actionlink asp.net-mvc-2

5
推荐指数
1
解决办法
3136
查看次数

MVC ActionLink如何指定text,actionname,controller和htmlattributes

我一直试图做一个像这样的动作链接:

<li>@Html.ActionLink("Home", "Index", "Invoice", new { id = "homelink" })</li>
Run Code Online (Sandbox Code Playgroud)

所以我拥有的是linkText,一个actionname,一个控制器名称和一个链接的id.

但是没有与之匹配的签名.最近的一个在控制器名称和htmlattributes之间具有路由值.我没有任何路线值,但我需要放在那里.

有人可以告诉我如何最好地解决这个问题吗?

asp.net-mvc actionlink

5
推荐指数
1
解决办法
2218
查看次数

如何使用MVC创建(图像)标题徽标(4)

我正在努力使用MVC(4)的Razor语法,希望能找到一个可以帮助我找到一个好的工作解决方案的人.

我想要一个可点击的徽标(图像)并创建以下代码.除了两件事之外,这有效.我没有看到图像显示,其次,在其他控制器中,路由出错(http4错误).

这就是我现在的表现:

剃刀:

<h1>@Html.ActionLink("siteHeader", "Index", null, new { @class = "site-logo"})</h1>
Run Code Online (Sandbox Code Playgroud)

要么

<h1>@Html.ActionLink("siteHeader", "Index", "Home", new { @class = "site-logo"})</h1>
Run Code Online (Sandbox Code Playgroud)

例如,当在不同的控制器(account/shoppingcart/etc.)中并点击徽标时,它会产生404.

CSS:

/ Site HeaderLogo /

a.site-logo  {     
 background: url(images/Solosoft.png) no-repeat top left;
 display: block;       
 width: 100px;       
 height: 100px;       
 text-indent: -9999px;  /*hides the link text*/ 
  } 
Run Code Online (Sandbox Code Playgroud)

提前致谢.

asp.net-mvc header actionlink razor graphical-logo

5
推荐指数
1
解决办法
2万
查看次数

如何处理.ajax post中的FileStream返回类型?

我通过以下代码发送JSON对象.控制器返回CSV格式的值,应提供promt打开或保存为CSV文件.我无法理解应该在什么代码中成功编写代码:function(result)

出口链接

Html.ActionLink("Export", "", "", null, new { @onclick = "return exportData();"})

function exportData() {

var searchViewModel = getExLogSearchModelData();
var path = getAbsolutePath("ExclusionLog", "ExportData");
$.ajax({
    url: path,
    cache: false,
    contentType: 'application/json; charset=utf-8',
    dataType: 'html',
    type: 'POST',
    data: JSON.stringify(searchViewModel),
    success: function (result) {
    },
    error: function (error) {
        $("#voidcontainer").html("Error");
    }
});
Run Code Online (Sandbox Code Playgroud)

}

控制器ActionResult

    public ActionResult ExportData(ExclusionLogSearchViewModel postSearchViewModel)
    {
        try
        {
            IEnumerable<ExclusionLogViewModel> exclusionLogData = null;
            exclusionLogcData = this._workerService.GetExclusionLogData(postSearchViewModel);

            return CSVFile(exclusionLogMembershipSyncData.GetStream<ExclusionLogViewModel>(), "ExclusionLogTables.Csv");
        }
        catch (Exception ex)
        {
                throw ex;
        }
        return null; …
Run Code Online (Sandbox Code Playgroud)

ajax asp.net-mvc actionlink actionresult

5
推荐指数
1
解决办法
4776
查看次数

使用ActionLink将null参数传递给控制器

我有一个列出一堆类别的视图:

<ul>
    <li>@Html.ActionLink("All", "Index", "Products")</li>
    @foreach (var item in Model.ProductCategories)
    {
        <li>@Html.ActionLink(item.Name, "Index", new { id = item.Id }, null)</li>
    }
</ul>
Run Code Online (Sandbox Code Playgroud)

如图所示,我应该得到一个类别链接列表,最上面的一个是"All",下面的是相应的类别名称,id传递给控制器​​.

我的控制器看起来像这样:

public ActionResult Index(int? id)
{
    var categories = _productCategoryRepository.GetAll().OrderByDescending(f => f.Name);
    var items = id == null
        ? _productItemRepository.GetAll().OrderBy(f => f.Name).ToList()
        : _productCategoryRepository.GetSingle((int)id).ProductItems.OrderBy(f => f.Name).ToList();

    var model = new ProductsViewModel()
                    {
                        ProductCategories = categories,
                        ProductItems = items
                    };

    return View(model);
}
Run Code Online (Sandbox Code Playgroud)

所以类别应该始终相同.但是,项目应显示出每一个项目,当ID当该特定类别的物品ID设置.

这一切都非常好,所以当我点击一个类别链接.我这样得到了网址:

/产品/首页/ 3

大!现在我点击"全部"链接,但它将我路由到/ Products/Index/3,即使我显然没有传递参数.我尝试传递一个空值:

@Html.ActionLink("Alle", …
Run Code Online (Sandbox Code Playgroud)

parameters controller actionlink razor asp.net-mvc-4

5
推荐指数
1
解决办法
3682
查看次数

Html.ActionLink从不同文件夹中的另一个控制器调用操作

我有一个简单的视图,如果登录成功并位于/ Login下,则会创建一个链接:

<div>
@Html.ActionLink("Add a new Organization", "AddOrganization", 
           "/Setup/AddOrganizationController", new { id = Session["ID"] }, null)
</div>
Run Code Online (Sandbox Code Playgroud)

在阅读其他类似的问题后,我尝试添加null之后,以及其他一些重载,但我无法使链接正常工作.当我点击链接时,它会带我去

http://setup/AddOrganizationController/AddOrganization
Run Code Online (Sandbox Code Playgroud)

哪个省略了需要在那里的localhost部分.最后没有null,它会尝试发送给我

/Login/AddOrganization
Run Code Online (Sandbox Code Playgroud)

我想要的只是一个链接,它将在AddOrganizationController控制器中运行一个动作,该控制器位于/ Setup目录下.该链接还应将会话ID作为参数传递给控制器​​.我怎样才能做到这一点?

c# asp.net-mvc actionlink asp.net-mvc-4

5
推荐指数
1
解决办法
2万
查看次数

ActionLink路由包含特定字符的值

我正在使用此动作链接向路由器发送路由值id,但我的id值是这样的config.xml ,这里是我的动作链接

 @Html.ActionLink("Destroy", "DeleteFile", "Files", new { id = "config.xml"})
Run Code Online (Sandbox Code Playgroud)

问题是,当我想点击此链接时,浏览器会将其理解为url最终结果config.xml

像这样

http://localhost:12380/Files/DeleteFile/config.xml
Run Code Online (Sandbox Code Playgroud)

并且不会转到它返回的控制器404 - not found.如何防止这种情况发生,并将其config.xml作为参数而不是文件?

这也是我的路线

routes.MapRoute(
              name: "delete files",
              url: "Files/DeleteFile/{id}",
              defaults: new
              {
                  controller = "Files",
                  action = "DeleteFile",
                  id= UrlParameter.Optional
              }
            );
Run Code Online (Sandbox Code Playgroud)

我也试过id ,filename但没有改变

这是我的控制器

[HttpGet]
        public ActionResult DeleteFile(string id)
        {
          return view("DeleteFile");
         }
Run Code Online (Sandbox Code Playgroud)

c# actionlink routevalues razor

5
推荐指数
1
解决办法
631
查看次数