标签: controller

asp.net mvc按区域名称查找控制器

我的目标是从它的名称和区域中找到一个控制器.如果我的当前httpContext区域与待定控制器位于同一区域内,我已成功完成此操作.但是,我无法接受ControllerFactory考虑区域的呼吁.这是我的代码:

public static ControllerBase GetControllerByName(this HtmlHelper htmlHelper, string controllerName)
    {
      IControllerFactory factory = ControllerBuilder.Current.GetControllerFactory();
      IController controller = factory.CreateController(htmlHelper.ViewContext.RequestContext, controllerName);
      if (controller == null)
      {
        throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "The IControllerFactory '{0}' did not return a controller for the name '{1}'.", factory.GetType(), controllerName));
      }
      return (ControllerBase)controller;
    }
Run Code Online (Sandbox Code Playgroud)

因为它RequestContext是一个参数,我为它添加了一个"区域"的路由值,但没有变化.我可以用requestContext做些什么来考虑区域吗?我是否需要覆盖控制器工厂 - 如果是这样,特别是处理区域区别的是什么?

更新:

以下是我所拥有的AreaRegistration示例:

public class StoresAreaRegistration : AreaRegistration
  {
    public override string AreaName { get { return "Stores"; } }

    public override void RegisterArea(AreaRegistrationContext context)
    {
      context.MapRoute( …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc controller asp.net-mvc-routing

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

没有路由匹配{:action =>"show",:controller =>"users"}

我正在尝试实现一个Twitter Boostrap登录表单,它将在每个页面上使用(因为导航栏是布局的一部分).

但是,在尝试下面的代码时,我收到以下错误:

No route matches {:action=>"show", :controller=>"users"}
Run Code Online (Sandbox Code Playgroud)

用户控制器:

class UsersController < ApplicationController

  def index
    @users = User.all
  end

  def show
    ...
  end

  def login
    ...
  end

end
Run Code Online (Sandbox Code Playgroud)

_navigation.html.erb:

<div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
    <%= form_for("user", :url => user_path) do |f| %>
        <%= f.label :email%>
        <%= f.text_field(:email, :size => 30, :class => 'login_field', :placeholder => 'Användarnamn')%>
        <%= f.label :password%>
        <%= f.text_field(:password, :size => 30, :class => 'login_field', :placeholder => 'Lösenord')%>

        <%= f.submit "Logga in", :class => 'login_submit btn btn-primary' …
Run Code Online (Sandbox Code Playgroud)

forms controller ruby-on-rails ruby-on-rails-3 twitter-bootstrap

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

当javaFX的控制器不足以显示内容时,它会在结尾显示"..."吗?

我的问题是我可以抓住显示"......"的事件吗?

※我的意思是javaFX有一个API来判断内容的结尾是否被替换为"..."?

事实上,我的问题的原因是,现在我们的测试人员希望我们在一个控制器(如Label)上设置TIP,如果它只是不足以显示.如果内容足以在控制器中显示,那么我们不需要添加提示.

controller javafx

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

传递值以在Zend Framework 2中查看

我正在尝试将现有的应用程序从Zend Framework 1转换为Zend Framework 2,我遇到了一些麻烦.

在原始应用程序中,我在控制器中有以下内容

function init()
{
    $this->initialize_values();
}
Run Code Online (Sandbox Code Playgroud)

我的所有控制器都扩展了一个基类,它具有该功能,如下所示.

protected function initialize_values()
{

    $this->_db = Zend_Registry::get('dbAdapter');
    $this->_current_user = new User(&$this->_db);

    $this->_auth = Zend_Auth::getInstance();
    if($this->_auth->hasIdentity())
    {
        $this->_current_user = unserialize($_SESSION['current_user']);
        $this->view->current_user = $this->_current_user;
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经复制了除设置该视图值的最后一行之外的所有功能.

在我为ZF2找到的所有示例中,它们都返回了一个数组或一个视图模型.我没有看到将值传递给未附加到动作函数的视图的方法.

php controller zend-framework2

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

ASP:用于在不同命名空间中具有相同名称的控制器的NET MVC4 url​​路由



在我的Asp.NET MVC4 Web项目中,我有许多控制器,我想将它们放在"控制器"文件夹下的子目录中.某些控制器由于其主要作业而具有相同的名称,但它们将被置于不同的子目录下,这意味着不同的名称空间.我想为这些控制器做一个url路由.如何使路由考虑存在具有相同名称的控制器的命名空间?你能在Global.asax文件中显示一些代码吗?
非常感谢.

controller url-routing subdirectory asp.net-mvc-4

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

在Spring @RequestMapping值中使用String数组"常量"

我应该指出Spring本身并不一定对这个问题至关重要,但是我在使用Spring时遇到了这种行为,所以这个问题使用了我在Spring中遇到这种情况的情况.

我有一个控制器类,它将请求GET和POST请求映射到特定表单的同一组URL.这个表单对于不同的语言环境有不同的URL,但是只有一个方法用于GET请求,一个用于请求,POST因为表单的控制器级别的逻辑对于每个语言环境站点是相同的(但是逻辑中更深层次的东西,如语言环境) - 特定验证,可能会有所不同).例:

@Controller
public class MyFormController {

    // GET request
    @RequestMapping(value={"/us-form.html", "/de-form.html", "/fr-form.html"},
            method={RequestMethod.GET})
    public String showMyForm() {
        // Do some stuff like adding values to the model
        return "my-form-view";
    }

    // POST request
    @RequestMapping(value={"/us-form.html", "/de-form.html", "/fr-form.html"},
            method={RequestMethod.POST})
    public String submitMyForm() {
        // Do stuff like validation and error marking in the model
        return "my-form-view"; // Same as GET
    }
}
Run Code Online (Sandbox Code Playgroud)

这样的形式GET和POST工作就好了.您会注意到String用于@RequestMapping值的数组是相同的.我想要做的是将这些URL放在一个位置(理想情况下是 …

java spring controller constants

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

在没有URL重定向的情况下调度到Kohana中其他控制器的控制器?

我对伟大的Kohana框架,管理员用户可以在后端几种页面选择与完全定制URL添加它们在菜单书面方式一个CMS.

Example of custom URL : "mmmm/about" or "aaa/bbb/release"
Run Code Online (Sandbox Code Playgroud)

我有一个数据库表,我存储了每个URL应显示的内容:

Example : 
URL : mmm/about     Pagekind : Content page ; (Page) Id : 7
URL : aaa/release   Pagekind : News         ; (News) Id : 1
Run Code Online (Sandbox Code Playgroud)

每种页面类型都有自己的控制器(因此它更干净,更易于管理,更容易添加新的页面类型):

Examples :
>>> In /application/classes/Controller/Pages :
class Controller_Pages() extends Controller_Template { 
    public function action_index(){
        ...
    }
}
>>> In /application/classes/Controller/News :
class Controller_News() extends Controller_Template { 
    public function action_index(){
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我有这样的路线,将所有内容发送到我的菜单控制器:

Route::set( 'menu_path', '(<menupath>)', array('menupath' => '.*?') )
->defaults(
    array(
        'controller' => …
Run Code Online (Sandbox Code Playgroud)

controller routes kohana

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

Rails在其他控制器中出现错误后呈现表单

在以下版本中,我有两个模型:客户端has_many产品,和Product属于client_to客户端。在客户展示视图中,我展示了一个表单,用于创建自动属于当前客户的新产品。客户端控制器中的show方法

def show
  @client    = Client.find(params[:id])
  @products  = @client.products.paginate(page: params[:page])
  @product = @client.products.new
  @product.client_id = @client.id
end
Run Code Online (Sandbox Code Playgroud)

和显示视图呈现局部

    <h1>New Product:</h1>
    <%= render 'shared/product_form' %>
Run Code Online (Sandbox Code Playgroud)

可行,产品正确创建。

发生验证错误时,我在产品的create方法和redirect_to客户端显示页面中设置了Flash。我在那里丢失了正确填写的数据。我尝试保存@product实例变量,该变量具有所有数据(包括错误的字段)

render client_path(client) 
Run Code Online (Sandbox Code Playgroud)

来自产品控制器,但这会产生错误

缺少模板/ clients / 17

地址为

http://localhost:3000/products
Run Code Online (Sandbox Code Playgroud)

我说错了吗?我知道渲染通常会渲染同一控制器的动作。我可以以某种方式从产品控制器渲染Client :: show吗?还有另一种方法来保存用户键入的数据吗?

controller render ruby-on-rails-3

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

如何将多个对象添加到ModelAndView中?

如何在Spring MVC 3的控制器中将多个对象添加到ModelAndView中?那可能吗?

validation spring controller model spring-mvc

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

在AngularJS控制器中获取$ resource调用的值

我正在使用AngularJS并且我已经进行了$ resource调用以获取单个值(例如,fetch使我得到14).

以下是我的控制器:

var MaxCount = $resource('/maxquestion/fetch', null, 
{
    getMaxQuestionCount: {method: 'GET', isArray: false}
});
$scope.maxQuestionCount = MaxCount.getMaxQuestionCount();
Run Code Online (Sandbox Code Playgroud)

现在我正试图$scope.maxQuestionCount在控制器中使用,做$scope.maxQuestionCount[0]了给我1并$scope.maxQuestionCount[1]给了我4

console.log($scope.maxQuestionCount)我,[object Object] console.dir($scope.maxQuestionCount)我There are no child objects

我糊涂了.如何获取值14?

javascript controller angularjs

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