如何将url与控制器操作相匹配

时间:2017-06-07 14:50:23

标签: asp.net-core asp.net-core-mvc

我很难获得我的控制器操作,因为这当前与默认路由匹配(我使用典型的默认路由配置)

function SelectProduct (props) {
const products = ['All', 'Beef', 'Lamb', 'Poultry'];
return (
<ul className='products'>
{products.map(function (prod) {
   return (
       <li
        style={prod === props.selectedProduct ? { color: '#d0021b' }:null}
                onClick={props.onSelect.bind(null, prod)}
                key={prod}>
                {prod}
            </li>
        )
    })}
</ul>
)};

class ProductCategoryRow extends React.Component {
constructor(props) {
super(props);

this.state = {
    list: list,
};
this.onDismiss = this.onDismiss.bind(this);
}

onDismiss(id) {
   const isNotId = item => item.objectID !== id;
   const updatedList = this.state.list.filter(isNotId);
   this.setState({ list: updatedList });
}

render() {
    return (
        <div className="container">
            { this.state.list.map(item => 
             <div key={item.objectID} className="product-category-row">
                        <div>{item.category}</div>
                        <div>{item.meatCut}</div>
                        <div>{item.cooking}</div>
                        <div>{item.price}</div>
                        <div>
                            <button
                            onClick={() => this.onDismiss(item.objectID)}
                            type="button"
                            >
                            Dismiss
                            </button>
                        </div>
                </div>
            )}
        </div>
    )
}
}

SelectProduct.propTypes = {
selectedProduct: PropTypes.string.isRequired,
onSelect: PropTypes.func.isRequired,
}

class Products extends React.Component {
constructor (props) {
    super(props);
    this.state = {
        selectedProduct: 'All',
        lists: null
    };
    this.updateProduct = this.updateProduct.bind(this);
}

componentDidMount () {
  this.updateProduct(this.state.selectedProduct);
}

updateProduct(prod) {
    this.setState(function () {
        return {
            selectedProduct: prod,
            lists: null
        }
    })
}

render() {
    return (
        <div>
            <SelectProduct
            selectedProduct={this.state.selectedProduct}
            onSelect={this.updateProduct}
            />
            <ProductCategoryRow selectedProduct={this.state.selectedProduct} />
        </div>
    )
}
}

export default Products;

为什么我的网址没有路由到此控制器操作?

我的打字稿

routes.MapRoute(
    name: "default",
    template: "{controller=Home}/{action=Index}/{id?}");

我的控制器操作

let headers = new Headers();
    headers.append('Content-Type', 'application/json');

    let update = new CollectionUpdate();
    update.collectionID = Number(this.collectionID);
    update.collectionName = "new name";

    let url = "/api/Collections/RenameCollection/";

    let json = JSON.stringify(update);
    debugger;
    return this.http
        .patch(url, json, { headers: headers })
        .map(res => res.json())
        .subscribe(
        result => {
            this.onRename(result as CollectionUpdate)
        });

1 个答案:

答案 0 :(得分:0)

将其更改为put操作有效。我想我会跟那个滚动。

        [HttpPut("[action]")]
    public Task<CollectionUpdate> RenameCollection([FromBody]CollectionUpdate update)