小编Mua*_*han的帖子

url.content(...)喜欢jquery或javascript中的方法?

可能重复:
java脚本中的Url帮助器

Url.Content(...)asp.net mvc helper方法返回等效的绝对URL.我在jquery或javascript中搜索一个像这样工作的方法...

因为,我想将javascript代码分成文件(.js),你知道该文件不支持javscript代码中的Url.Content(...)....

url(...)jquery方法不像Url.Content()

更新日期:2011年1月22日

嗨伙计们,我有一个解决方法:

在.cshtml文件中,我创建了一个' GetPath '函数,它返回包含域名的绝对路径,并且可以在任何.js文件中访问.在任何ASP.NET MVC视图(.cshtml或.aspx或.vbhtml)中包含以下代码:

<script type="text/javascript">
    var fullPath = '@HttpContext.Current.Request.Url.Scheme://@HttpContext.Current.Request.Url.Authority';
    function GetPath(url) {
        return fullPath + url;
    }
</script>
<script src="@Url.Content("~/JavaScriptFile.js")" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

以及任何javascript文件中的代码.

$(function () {
    alert(GetPath('/Content/Site.css'));
});
Run Code Online (Sandbox Code Playgroud)

结果是:http://www.yourDomain.com/Content/Site.css 或localhost:1234/Content/Site.css >> Visual Cassini服务器

你只需要更换@Url.Content("")GetPath('')任何.js文件...

http://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html

asp.net-mvc jquery

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

保护(加密)web.config文件中的密码(asp.net)

 <system.net>
  <mailSettings>
   <smtp from="email@domain.com" deliveryMethod="Network">
    <network clientDomain="www.domain.com" host="smtp.live.com" defaultCredentials="false" port="25" userName=" email@domain.com " password="password" enableSsl="true" />
   </smtp>
  </mailSettings>
 </system.net>
Run Code Online (Sandbox Code Playgroud)

这是我需要加密密码的情况.我在网上搜索和搜索了很多,但我无法再加密了.

任何人都可以帮助我以一种简单但安全的方式做到这一点.

asp.net

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

$ .each(someData.split(',')=>返回连接字符串,而不是项目数组

我正在使用asp.net mvc - 带jQuery的ajax ...我有一个名为" Books " 的模型类型,它包含一个属性" TableOfContents ",该属性包含以下格式的数据:

TableOfContents = "1,2,4,6,9,17,28";
Run Code Online (Sandbox Code Playgroud)

Json动作方法,重新启动Book对象如下所示:

public JsonResult GetBook(int id) {
    return Json(_bookRepository.Current(id), .....AllowGet);
}
Run Code Online (Sandbox Code Playgroud)

遵循我想要显示的列表图像的样式.

替代文字

在C#(Razor)我能做到这一点,

var splitted = Model.TableOfContents.Split(‘,’);
@foreach(var number in splitted) {
     <li><img src=”@Url.Content(“~/Content/Images/img-“ + number + “.gif”)” /> </li>
}
Run Code Online (Sandbox Code Playgroud)

此代码100%工作并显示图像,如上图所示.

我想用jQuery做同样的事情,因为我正在使用带有jQuery的ASP.NET MVC Ajax.这是jQuery脚本,我通过jQuery从MVC获取数据.

<script type="text/javascript">          
        function GetBook(id) {
            var url = '@Url.Content("~//Monthly/CurrentBook?id=")' + id;

            $.post(url,
            null,
            function (book) {
                $('#bookResult' + book.ID).html(
                '<a href="@Url.Content("~/BookDetails/")' + book.ID + '">Click to View Details</a>'
                + '<div><p style=" text-align:center;">'
                + …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery json

6
推荐指数
1
解决办法
3万
查看次数

使用javascript检查客户端上缓存的CDN jQuery

我可以使用JavaScript来检查JQuery是否(已经)在目标Web浏览器(用户)上下载(缓存)了吗?例如:

If (JQuery-from-Microsoft-CDN-downloaded)
    Then use http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js
Else if (JQuery-from-Google-APIs- downloaded)
    Then use http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
Else if (JQuery-from-code.jquery.com- downloaded)
    Then use http://code.jquery.com/jquery-1.4.4.min.js
Else use jQuery from my own website.
Run Code Online (Sandbox Code Playgroud)

意思是使用JavaScript的能力,以检查其中的一个是否被目标用户(网页浏览器)下载,如果没有的话,从我自己的网站上使用jQuery否则,如果为true,则使用JQuery该版本是在目标用户下载.

jquery

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

jquery mobile上的$ .ajax

$ .ajax使用jquery移动框架无法正常工作...

它只是让我们下载html文件....

如果我们想调用'ActionMethod'那么它不起作用:

$.ajax({
   url:'Home/CallMe',
   success: function(result) {
    alert(result);
   }  // edited
});
Run Code Online (Sandbox Code Playgroud)

它挂起了系统......

我正在使用iPhone模拟器进行测试....

任何人都可以让我知道为什么上面不起作用,为什么下面的工作使用jquery移动框架?

$

.ajax({
       url:'htmlFile.htm',
       success: function(result) {
        alert(result);
      } // this line is edited later

    });
Run Code Online (Sandbox Code Playgroud)

编辑: 我想告诉你的另一件事是我正在使用ASP.NET MVC ...

编辑: 您可以尝试的最简单的动作方法示例是:

public JsonResult CallMe()
{
   return Json("I'm your response");
}
Run Code Online (Sandbox Code Playgroud)

[HttpPost]也可以应用,如果你想......

jquery jquery-mobile

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

如何将音频+视频作为一个上传到服务器?

如何以单一文件格式将基于RecordRTC的音频+视频录制上传到服务器?

RecordRTC似乎生成两个单独的文件:一个用于音频(如WAV),另一个用于视频(如WebM).如何在PHP服务器上同时上传这两个文件?

recordrtc

3
推荐指数
1
解决办法
2861
查看次数

asp.net mvc中的远程属性 - 在某些情况下限制了我们的模型

在ASP.NET MVC3中使用远程属性时,我遇到了意外情况.

我使用的模型类型:

using System;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;

namespace dTweets.Models
{
    // at first time, user should create his account with unique username
    // as in twitter.com, user do
    public class UserMetadata
    {
        [HiddenInput]
        internal int Identity { get; set; }


        [Remote("IsUserExist", "Account")] // at any HttpPost, username should
                                           // be unique – not appropriate if 
                                           // updating/editing this model later

        [Required(ErrorMessage = "username should be unique")]
        public string UserName { get; set; } // user cannot change it, …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

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

标签 统计

jquery ×4

asp.net-mvc ×3

asp.net ×1

jquery-mobile ×1

json ×1

recordrtc ×1