Asp.net mvc 4 如何将值余烬视图传递给控制器

Asp.net mvc 4 如何将值余烬视图传递给控制器,asp.net-mvc-4,ember.js,handlebars.js,Asp.net Mvc 4,Ember.js,Handlebars.js,我是新来的美丽恩伯js开发 我已经完成了下面的代码查看 {{view "select" content=model prompt="Please select a name" selectionBinding="" optionValuePath="content.body" optionLabelPath="content.title"}} 使用以下Json posts = [{ title: "Raja", body: "There are lots o

我是新来的美丽恩伯js开发

我已经完成了下面的代码查看

 {{view  "select"  content=model    prompt="Please select a name"  selectionBinding=""    optionValuePath="content.body" optionLabelPath="content.title"}}
使用以下Json

posts = [{
    title: "Raja",
    body: "There are lots of à la carte software environments in this world."
}, {
    title: "Broken Promises",
    body: "James Coglan wrote a lengthy article about Promises in node.js."
}];
和路由器

App.InRoute = Ember.Route.extend({
    model: function () {    

        return posts;      
    }
});
我的要求是将组合框选择的值传递给控制器

以及如何在.NETMVC4中访问该值

您只需要设置selectionBinding=someModelAttribute,双向数据绑定将负责设置模型上的选定值。

您的选择视图的值属性需要绑定到控制器上的属性:

将以下内容添加到视图的属性中:value=selectedItem

在控制器中:

添加selectedItem

现在,您可以将其发送到Api端点。您可以创建一个操作处理程序并使其发生在那里。下面是一个简单的例子:

在你的车把模板

提交

在.NETAPI控制器中


你真的应该研究一下如何使用余烬数据,这太棒了。

我正在尝试显示警报操作:{submit:function{alertthis.get'selectedItem';}显示空值正如Asgaroth所指出的,您还可以绑定到模型上的属性…或者控制器,两者都可以。如果您使用value,请不要使用selectionBinding。您能简单解释一下吗
App.InController = Ember.Controller.extend({

alert("combobox selected item")
});
 public class ValuesController : ApiController
    {
  string value=    combo box selected value
}
App.InRoute = Ember.Route.extend({

    selectedItem: null,

    model: function () { 
      return posts;      
    }
});
App.InRoute = Ember.Route.extend({

   selectedItem: null,

   model: function () {
     return posts;      
   },

  actions: {
     submit: function(){
        $.ajax('/api/yourEndPoint', {type: 'POST', data: {body: this.get('selectedItem')} })
  }
}
});
public IHTTPActionResult Post(string body){
   //.NET's Model Binder will correctly pull out the value of the body keyvalue pair.
   //Now do with "body" as you will.
}