Tag: asp.net mvc 4

MVC4 SignalR“signalr / hubs”501未实现错误

更新:切换到IIS Express而不是Visual Studio开发服务器修复了501错误。 我正在尝试让SignalR在我的MVC4应用程序中工作,但我遇到了一个奇怪的501错误。 我已经按照几个不同的教程,但结果总是一样的。 任何帮助,将不胜感激。 我正在使用Visual Studio 2012 Pro RC,我通过包管理器控制台安装了SignalR 0.5.1。 我的代码: 布局 视图 $(function () { // capture the client IP var clientIp = $(“#clientip”).val(); // create the SignalR proxy var userlink = $.connection.userlink; // create our callback for the proxy userlink.updateViewCount = function (message) { $(‘#view-updates’).html(” + message + ”); }; // […]

无法使用Headers =“application / x-www-form-urlencoded”编码我的JSON对象insdie我的WebClient UploadString

我正在开发一个ASP.Net MVC 4 Web应用程序,我需要将JSON对象发布到第三方API。 现在我需要通过将内容类型设置为application/x-www-form-urlencoded来编码我的JSON数据,如API文档中所述。 所以我尝试了以下内容,将Content-Type指定为wc.Headers[“Content-Type”] = “application/x-www-form-urlencoded”; : – var data = JsonConvert.SerializeObject(mainresourceinfo); using (WebClient wc = new WebClient()) { string url = currentURL + “resources?AUTHTOKEN=” + pmtoken; Uri uri = new Uri(url); // wc.Headers[HttpRequestHeader.ContentType] = “application/x-www-form-urlencoded”; wc.Headers[“Content-Type”] = “application/x-www-form-urlencoded”; crudoutput = wc.UploadString(uri, “INPUT_DATA=” + data); } 但是数据仍然没有被编码..如果我在我的JSON字符串中发送一个123%456类的值,它将被保存为第三部分系统内的123E6t 。 现在作为一种解决方法,我使用WebUtility.UrlEncode(data)手动编码JSON对象,然后将其发送到第三方API,我可以看到123%456等值将正确保存…但我不知道想要手动编码数据,我想设置内容类型来指定编码…这可能吗?

更新会员资产。 方法不受支持

我试图研究我现在几个小时没有进展的例外情况。 我只是尝试使用以下代码更新成员资格配置文件: MembershipUser user = Membership.GetUser(username); user.IsApproved = false; Membership.UpdateUser(user); 所以问题在于上面代码示例中的最后一行。 服务器抛出exception,指出不支持指定的方法。 我没有构建错误,我相信我正在使用正确的库。 知道为什么会出现这样的事情吗? Server Error in ‘/’ Application. Specified method is not supported. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. […]

将video上传/保存到数据库或文件系统

我之前从未尝试过保存video,因此我对此并不了解。 我知道如果video很小我可以转换为字节数组并保存到数据库,但为了更高效我想学习如何将任何上传的video保存到我的服务器文件,然后只保存文件的路径我的数据库表中的video。 我完全不知道如何开始这样做。 我在下面看过这个例子,但不太清楚它在做什么。 对我来说,似乎它保存了任何用户上传到App_Data文件夹的任何上传video。 是对的吗? 任何帮助是极大的赞赏。 [HttpPost] public ContentResult UploadFiles() { var r = new List(); foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; string savedFileName = Path.Combine(Server.MapPath(“~/App_Data”), Path.GetFileName(hpf.FileName)); hpf.SaveAs(savedFileName); // Save the file r.Add(new ViewDataUploadFilesResult() { Name = hpf.FileName, Length = hpf.ContentLength, Type = […]

如何将JavaScript文件的链接添加到某个ASP .NET MVC页面的标题中

如何将JavaScript文件的链接添加到某个ASP .NET MVC页面的标题中? 可以说有_Layout.cshtml和About.cshtml,我需要将一些javascript文件放到About.cshtml的标题中。 我只是指那个页面。 http://www.dotnetcurry.com/ShowArticle.aspx?ID=636 怎么做?

asp.net MSDeployEnableWebConfigEncryptRule无法加密web.config

我已将true到.pubxml文件以加密Web配置文件。 但是,在发布时,我收到以下错误。 我不知道除了在.pubxml中插入true之外,web.config文件中是否还需要额外的设置 错误:Web部署任务失败。(无法加密目标web.config。有关详细信息,请访问: http : //go.microsoft.com/fwlink/?LinkId = 221672 #ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG 。) 注意:#ERROR_FAILED_TO_ENCRYPT_WEB_CONFIG不会出现在给定链接的任何位置。 我怎么能解决这个错误? (注意:我不希望在发布之前在本地预加密web.config文件)

RenderPartial,模型作为参数

我得到一个类型错误,但我不明白为什么,我有一个View,一个ViewModel,一个PartialView和一个Model。 视图礼物将giftViewModel作为模型。 giftViewModel包含Model LoginModel(登录)的实例。 partialView LoginPopUp将LoginModel作为模型。 我尝试在礼物视图中渲染partialView LoginPopUp,将其作为模型传递给我。 我收到这个错误: The model item passed into the dictionary is of type ‘GiftViewModel’, but this dictionary requires a model item of type ‘LoginModel’. 这是代码: GiftViewModel.cs public class GiftViewModel { public LoginModel login { get; set; } […] } 礼品/ Index.cshtml @model GiftViewModel @section content{ @{Html.RenderPartial(“LoginPopUp”, Model.login);} } LoginPupUp.cshtml […]

ApiController操作无法从查询字符串解析数组

使用Visual Studio 2012.2,MVC4 Web应用程序。 我有这样的请求来到我的ApiController: http://localhost/api/keys?ids[]=1&ids[]=2&ids[]=3 我的印象是以下方法应该能够自动从ids []数组中检索值: public KeysModel Get(int[] ids){…} 但是,当出现上述请求时,“ids”参数的值为null。 我已经检查过HttpContext.Current.Request.QueryString有ids的值,我可以这样对待它们,但这会使unit testing变得更难。 我也尝试使用List ids,[FromUri],[FromUri(Name =“ids []”)],对象id和字符串id(有趣的是,当ids是一个字符串变量时,其中的值是“ (采集)”

将文本框值从视图传递到按钮

视图: @using (@Html.BeginForm(“Show”, “test”, FormMethod.Post)) { @Html.LabelFor(model=> model.Show) @Html.TextBox(“txtvalue”, null) } 和控制器中的两个动作方法, public ActionResult Show(string txtvalue) { … } public ActionResult Go(string txtvalue) { … } 根据哪个按钮单击,它应该转到相应的操作方法并传递文本框的值。 任何人都可以建议我这样做的方式。 我绕着脑袋想不通。

生成报告时,不能像方法一样使用不可调用的成员“文件”

我在之前的项目中使用了一种生成报告的方法,并尝试在新项目中使用相同的方法。 但是,我遇到“非invocable成员’文件’不能像方法一样使用”错误和文件无法识别。 通过查看文件的引用,它似乎是上一个项目中的FileContentResult Controller.File() ,但是新项目中的System.IO.File() (即使我使用System.IO删除;来自引用行,我遇到“名称’文件’在当前上下文中不存在”错误)。 有什么想法解决这个问题吗? public static FileResult GenerateReport() { EmployeeTableAdapter ta = new EmployeeTableAdapter(); EmployeeDS ds = new EmployeeDS(); ds.Employee.Clear(); ds.EnforceConstraints = false; ta.Fill(ds.Employee); ReportDataSource rds = new ReportDataSource(); rds.Name = “ReportingDataSet”; rds.Value = ds.Employee; ReportViewer rv = new Microsoft.Reporting.WebForms.ReportViewer(); rv.ProcessingMode = ProcessingMode.Local; rv.LocalReport.ReportPath = System.Web.HttpContext.Current. Server.MapPath(“~/Reporting/Employee.rdlc”); rv.LocalReport.EnableHyperlinks = true; rv.LocalReport.EnableExternalImages = […]