How do I bind a model during an action?

I have a dynamic url processor

public ActionResult DynamicUrl(string slug = null)

      

this method works via slug (btw what does slug stand mean?) and works if the slug displays a product or searches for a product.

As part of a product search, I have a page = 1 querystring parameter.

E.g. /Womens/Dresses?page=2

      

I used to do this in a normal product search activity that associates a page request with the ProductSearch model.

public ActionResult Results(ProductSearchModel  searchModel)

      

How to bind a query string during an action? for example

public ActionResult DynamicUrl(string slug = null)
{
    ProductSearchModel psm = new ProductSearchModel();

    //Auto bind psm here.
    // E.g. Controller.BindModel(psm);
}

      

Hope I disagree with this.

+3


source to share


1 answer


Do you mean:

UpdateModel(psm);

      

This will bind the current collection of forms to the specified model.



You can also use:

TryUpdateModel(psm);

      

This version won't throw an exception if something doesn't work, and returns true

or false

.

+2


source







All Articles