我正在开发一个控制器,它是一个非常扁平的页面层次结构的一部分,看起来该站点的一个部分可能有十几种操作方法,不包括它们相应的后期操作.是否有一个很好的方法来打破这个控制器,同时仍然保留部分名称?我不希望控制器类失控.
我有一个问题,我无法在我的控制器中加载我的库:S
我收到此错误:消息:未定义属性:Profil :: $ profileWall
我的图书馆:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ProfileWall
{
private $CI;
public function __construct()
{
$this->CI =& get_instance();
}
public function wallShow()
{
$this->CI->load->model('profil_model');
return $this->CI->profil_model->wallGet($this->CI->uri->segment(3));
}
}
Run Code Online (Sandbox Code Playgroud)
和我的控制器
function index()
{
$this->load->model('profil_model');
$data['query'] = $this->profil_model->vis_profil($this->uri->segment(3));
//Henter lib profilwall så man kan vise wall beskeder i profilen
$this->load->library('profileWall');
$data['queryWall'] = $this->profileWall->wallShow();
$data['content'] = 'profil_view';
$this->load->view('includes/template', $data);
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
在Global.asax文件中,我管理一些线程,并且 - 从Controller - 我需要调用一个线程的事件.是否可以访问该线程?
我必须在单击自定义后退按钮后从当前视图控制器弹出到HomeScreenViewController,后者在主窗口上添加为灯箱.我使用以下代码:
HomeScreenViewController *homeController = [[HomeScreenViewController alloc]
initWithNibName:@"HomeScreenViewController" bundle:nil];
[self.navigationController popToViewController:homeController animated:YES];
[homeController release];
Run Code Online (Sandbox Code Playgroud)
我遇到异常崩溃: Tried to pop to a view controller that doesn't exist.
如何实施?实施它需要做哪些改变?
是否可以创建一个具有控制器的局部视图,可以使用另一个视图调用该控制器
Html.RenderAction(...)
但是没有相同的控制器可以通过URL访问?
所以举个例子
public class ArticlesController : Controller
{
public ActionResult HomeList()
...
}
Run Code Online (Sandbox Code Playgroud)
提供我的网页底部的最新文章列表.
所以我称之为
_Layout.cshtml
但是我不希望有人来
mysite.com/Articles/HomeList
由于各种原因(安全,搜索引擎优化等)看到相同的列表
谢谢
编辑:
由于Russ的帮助,我最终使用了自己的属性类:
public class ChildActionOnly404Attribute : FilterAttribute, IAuthorizationFilter
{
void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)
{
if (!filterContext.IsChildAction)
{
throw new HttpException(404, "");
}
}
}
Run Code Online (Sandbox Code Playgroud) 从Controller返回不同的视图非常容易:
return View("../Home/Info");
Run Code Online (Sandbox Code Playgroud)
但是,我需要在Info视图中使用一个模型.我在Info()动作结果方法中有很多东西.我可以复制它,并有这样的事情:
var infoModel = new InfoModel {
// ... a lot of copied code here
}
return View("../Home/Info", infoModel);
Run Code Online (Sandbox Code Playgroud)
但那是不合理的.
当然我可以重定向:
return RedirecToAction("Info");
Run Code Online (Sandbox Code Playgroud)
但这样URL就会改变.我不想更改URL.这非常重要.
我创建了一个解决方案有两个项目:一个是一个类库使用自托管Web API(的帮助下创建http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self -host-a-web-api),第二个是用TopShelf创建的Windows服务.此解决方案的目的是使用Web API获取服务的状态报告.
一切正常,但是当我在目标解决方案中重新创建我的解决方案时,整个应用程序都无法正常工作.Windows服务似乎是工作,但是当我输入localhost:8080 /测试这是假设以查看OK(它在开头提到的单独的测试解决方案所做的),它抛出一个错误(可以看作是一个xml):
Message: No HTTP resource was found that matches the request URI 'http://localhost:8080/Test'.
MessageDetail: No type was found that matches the controller named 'Report'.
Run Code Online (Sandbox Code Playgroud)
在包含SelfHost的项目中有一个ReportController(继承自ApiController)但不知何故它是"可见的".我猜了(我相信这是一个愚蠢的猜测)并将其移至Windows服务项目,但它也无法正常工作.
谁能告诉我我面临的问题是什么?为什么在简单的解决方案中没有看到控制器?
编辑: 我的路由看起来像这样:
var config = new HttpSelfHostConfiguration(String.Format("http://localhost:{0}", port));
config.Routes.MapHttpRoute("API Default", "{action}", new { controller = defaultControllerName });
Run Code Online (Sandbox Code Playgroud)
哪里
defaultControllerName = "Report";
Run Code Online (Sandbox Code Playgroud) 我希望能够有一个链接按下时根据控制器动作更新一个属性.我怎么能这样做?我是否必须创建单独的更新路由?我是新来的,所以请耐心等待.
调节器
def completed
@meeting = Meeting.find(params[:id])
if @meeting.day_of_meeting == @meeting.days
@meeting.update_attribute(:day_of_meeting, '1')
redirect_to :back
else
@meeting.increment!
redirect_to :back
end
end
Run Code Online (Sandbox Code Playgroud)
模型
def increment!
update_attribute(:day_of_meeting, day_of_meeting + 1)
end
Run Code Online (Sandbox Code Playgroud)
视图
<%= link_to meetings_completed_path(@meeting), remote: true do %>
Run Code Online (Sandbox Code Playgroud)
路线
resources :meetings do
get 'meetings/completed'
end
Run Code Online (Sandbox Code Playgroud) 我在mvc-angularjs中创建一个web应用程序,我正在使用ngroute.
我的布局中的Angularjs控制器使用html代码:
<div class="container body-content" ng-app="MyApp">
<br />
<br />
<br />
<div style="float:right;">
<a href="#" class="btn btn-danger">Sign Out</a>
</div>
@RenderBody()
<hr />
</div>
<script>
(function () {
var app = angular.module('MyApp', ['ngRoute', "ngStorage"]);
app.controller('myctrllayout', function ($scope) {
});
})();
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的欢迎页面:
<div ng-controller="welcome">
</div>
<script>
angular.module('MyApp',[])
.controller('welcome', function ($scope) {
});
</script>
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我收到以下错误
错误:$ controller:ctrlreg未注册具有此名称的控制器.
名称为"welcome"的控制器未注册.
当我将我的应用程序更改('MyApp',[])为('MyApp'):
模块'MyApp'不可用!您要么错误拼写了模块名称,要么忘记加载它.如果注册模块,请确保将依赖项指定为第二个参数.
我正在尝试在我的ASP.NET Core 2项目中创建文件上载功能.
我将POST调用发送到WEBApi服务时收到此响应:
状态代码:415; 不支持的媒体类型
我的控制器操作如下所示:
[HttpPost]
[Route("Upload")]
[Authorize]
public Guid Post([FromBody]IFormFile file)
{
Stream readStream = file.OpenReadStream();
byte[] fileData = new byte[file.Length];
readStream.Read(fileData, 0, fileData.Length);
return _printServiceManager.SaveFile(fileData);
}
Run Code Online (Sandbox Code Playgroud)
我从我的Angular 6客户端应用程序和Postman调用它,但没有任何变化.我在这里找到了一个关于这个主题的问题,但给出的解决方案是将我的标题更改为"Content-Type:application/json".没有变化.
然后我尝试在网上搜索其他一些提示,但我找到的唯一一个提醒我再次更改内容类型标题:"Accept:application/json".不行.
也许我问一些简单的或我应该知道作为一个Web开发人员,但我来自一个后端导向的职业生涯,我试图找出什么是错我的代码.因此,如果您有关于该主题的完整资源,请分享!
提前致谢.
controller ×10
asp.net-mvc ×2
c# ×2
action ×1
angularjs ×1
asp.net ×1
asp.net-core ×1
codeigniter ×1
global-asax ×1
iphone ×1
load ×1
ngroute ×1
routing ×1
self-hosting ×1
uinavigation ×1
upload ×1
view ×1