我正在尝试在MVC 5中使用路由属性.我在Visual Studio中创建了一个空的MVC项目进行实验,到目前为止我无法使路由工作.我正在使用此页面作为参考.我有最新的程序集,并将所有NuGet软件包更新到最新版本.
这是我的代码:
// RouteConfig.cs
namespace MvcApplication1
{
using System.Web.Mvc;
using System.Web.Routing;
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Enables MVC attribute routing.
routes.MapMvcAttributeRoutes();
// The default route mapping. These are "out of the bag" defaults.
routes.MapRoute(null, "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
}
}
}
// TestControler.cs
namespace MvcApplication1.Controllers
{
using System.Web.Mvc;
public class TestController : Controller
{
public ContentResult Output1()
{
return Content("Output …Run Code Online (Sandbox Code Playgroud) 我正在尝试CodeIgniter用户指南版本2.2.0中的教程.我只是按照粘贴的代码,但我收到此错误消息.这里到底有什么不对?
Fatal error: Non-abstract method News_model::__construct() must contain
body in /var/www/leomel/application/models/news_model.php on line 3
Run Code Online (Sandbox Code Playgroud)
源代码:
<?php
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_model');
}
public function index()
{
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';
$this->load->view('templates/header', $data);
$this->load->view('news/index', $data);
$this->load->view('templates/footer');
}
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
}
Run Code Online (Sandbox Code Playgroud) 今天我试图将我的代码转换为PHP/MySQLi OOP代码.
class Database
{
private $host;
private $user;
private $password;
private $db;
private $mysqli;
function __construct()
{
$this->host = "*****";
$this->user = "*****";
$this->password = "******";
$this->db = "*****";
$this->mysqli = new mysqli($this->host, $this->user, $this->password, $this->db);
if (mysqli_connect_errno()):
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
endif;
}
}
Run Code Online (Sandbox Code Playgroud)
这是查询的脚本:
include_once("WD_Config/database.php");
class Adressen_Db
{
function __construct()
{
$this->database = new Database();
}
public function selecteer()
{
$query = "SELECT * FROM wd_adressen WHERE verborgen = 0 ORDER BY naam ASC";
$result = …Run Code Online (Sandbox Code Playgroud) 我承认我是MVC razor/jquery的新手.
在我的_Layout.cshtml中,这有效:
<body onload="alert('in the body');">
Run Code Online (Sandbox Code Playgroud)
这是_Layout.cshtml中的代码:$(document).load不会触发($(window).load也没有)
@Styles.Render("~/Content/Styles/Courses.css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jquery-1.7.1.min.js")
<script type="text/javascript">
$(document).load(function() {
alert('test');
</script>
</head>
<body>
Run Code Online (Sandbox Code Playgroud)
这是在页面运行时呈现的,使用"查看源代码"获取下面的html
<link href="/Content/Styles/Courses.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.5.3.js"></script>
<script src="/Scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).load(function() {
alert('test');
</script>
</head>
<body>
Run Code Online (Sandbox Code Playgroud)
我将jquery和javascript移动到Index.chstml文件,它仍然不会触发.我首先通过在VS 2010中拖动来引用.js文件.这不起作用.然后我在_Layout.chshtml中尝试了这种语法; 不起作用:
@Scripts.Render("~/Scripts/jquery-1.7.1.min.js")
Run Code Online (Sandbox Code Playgroud)
任何见解/帮助/....solutions欢迎谢谢
我遇到了以下问题:
用户访问网站,点击"添加",然后发送回Controller,模型被检索并再次发送给View.在内部视图中,我检查Model是否为null并显示数据.
@if (Model != null)
{
<div id="appInfo">
<table>
<tr>
<th>@Html.DisplayNameFor(x => Model.tytul)</th>
<th>@Html.DisplayNameFor(x => Model.kategoria.nazwa)</th>
<th>@Html.DisplayNameFor(x => Model.liczba_ocen)</th>
<th>@Html.DisplayNameFor(x => Model.avg_ocena)</th>
<th>@Html.DisplayNameFor(x => Model.typ)</th>
</tr>
<tr>
<td>@Model.tytul</td>
<td>@ViewData["kategoria"]</td>
<td>@Model.liczba_ocen</td>
<td>@Model.avg_ocena</td>
<td>@Model.typ</td>
</tr>
</table>
</div>
<div>
@using (Html.BeginForm("Confirm", "Wydawca", new { app = @Model }))
{
<input type="submit" value="Cofirm it" />
}
</div>
Run Code Online (Sandbox Code Playgroud)
在结束按钮上创建"确认它",单击它后会调用确认方法,但应用变量始终为空.如果我将其值设置为除模型之外的任何值.
[HttpPost]
public ActionResult Confirm(aplikacja app)
{
...
}
Run Code Online (Sandbox Code Playgroud)
在创建按钮"确认它"模型不为空时,我检查了.你碰巧知道出了什么问题吗?
生成的HTML
<form action="/Wydawca/Confirm?app=Adds.Models.aplikacja" method="post">
<input type="submit" value="Zatwierd?" />
Run Code Online (Sandbox Code Playgroud)
我有我的模特,
public IDictionary<int, string> QuestionSetList { get; set; }
Run Code Online (Sandbox Code Playgroud)
我不能在我的控制器中使用这个QuestionSetList,当它执行时,它抛出一个NullReferenceException,说:对象引用没有设置为对象的实例.我有我的代码,
model.QuestionSetList.Add(QuestionSetNo,QuestionSetTopic);
Run Code Online (Sandbox Code Playgroud)
请告诉我如何解决这个问题.
我的web api中有一个post方法,它返回一个字符串,我从客户端调用该方法.我如何获得返回的值.
发布方法
public String Post(Models.SQNotificationDataAccessRepository.NotificationEntry notificationEntry)
{
String externalReferenceID = String.Empty;
if (notificationEntry == null)
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
externalReferenceID= dbTransactionLayer.PopulateEsiTable(notification);
return externalReferenceID;
}
Run Code Online (Sandbox Code Playgroud)
客户
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:12819/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Notification notification = new Notification()
{
id = 102,
To = new String[] { "jamesBond@yahoo.com", "cmsds@email.com" },
Title = "Notification WebService Client Test",
MessageBody = "The message body will go there",
DelieveryType = "Email",
Response = true
};
HttpResponseMessage …Run Code Online (Sandbox Code Playgroud) 我在我的MVC5应用程序(Oracle后端)中有一种情况,其中我必须在转移到视图的GET时存储当前URL(此URL包含用户以前的导航位置以及在此处列出的任何/所有排序/过滤条件数据网格).
起初我以为我已经通过使用Session变量来解决这个问题Session["returnURL"],但是当它在我的localhost上运行时,许多尝试仍然导致我的会话变量NullReferenceException在我的Production Server上执行期间抛出.我现在在GET Edit操作上有以下内容:
if (Request.UrlReferrer.AbsoluteUri != null)
{
ViewBag.ReturnURL = Request.UrlReferrer.AbsoluteUri;
}
else
{
ViewBag.ReturnURL = null;
}
Run Code Online (Sandbox Code Playgroud)
如果上面的值不为null,我将它存储在ViewBag中以访问我的View(将其指定为hrefon actionlink):
@{
if (ViewBag.ReturnURL == null)
{
<span class="btn btn-default">
@Html.ActionLink("Back to List", "Index", "Home", new { @class = "btn btn-default" })
</span>
}
else
{
<a href="@ViewBag.ReturnURL"><span class="btn btn-default">Back to List</span></a>
}
}
|
<input type="submit" value="Save" class="btn btn-primary" />
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,当我尝试将更改保存到我的记录(从而进入我的编辑操作的POST)时,我收到:
Server Error in '/' Application. Value cannot be null or empty. Parameter …
让我设置场景:
我有一个"Item"类,它有不同的食物(如胡萝卜,苹果等).这链接到"项目"表.一切都很好.
在我迁移的旧框架中,我还有一个"Complete Protein"类,它在构造函数中需要一个Item对象.然后,这个"CompleteProtein"对象将能够执行复杂的查询和方法,并包含有关"完整蛋白质"的一般信息.
这适合Laravel?它似乎不是一个雄辩的模型,因为它不直接与数据库中的任何表相关,但它确实进行数据库查询.它确实有依赖注入(Item),以及类中的复杂方法和常量.
我应该以某种方式使这些适合"Item"类吗?我觉得那会很混乱.
我有一个如下所示的模型
public class security
{
public long id { get; set; }
public long user_id { get; set; }
public long submenu_id { get; set; }
public long module_id { get; set; }
public long flag { get; set; }
public string module { get; set; }
public string submenu { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果用户有权访问该菜单,flag则将在其中10
我可以使用 pagedlist 在视图中显示它
@foreach (var item in Model)
{
<tr class="">
<td>
@if (item.flag == 1)
{
<input type="checkbox" name="flags[]" …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×7
c# ×3
php ×3
razor ×3
codeigniter ×1
eloquent ×1
html-helper ×1
jquery ×1
laravel ×1
laravel-5.1 ×1
mysqli ×1
viewbag ×1