url.action является:как удалить параметры строки запроса в URL в mvc4 с RazeR использованием url.action
<li><a href="@Url.Action("CategoryLevel", "Product", new { CategoryId = @item._categoryId, ProductName = @Html.Raw(item._categoryName) })">@Html.Raw(item._categoryName)</a></li>
он работает нормально, но я не хочу, чтобы отобразить строку qyery в URL
URL является:
http://localhost:99/Product/CategoryLevel?CategoryId=16&ProductName=Common%20Conditions
i want to display this as
`http://localhost:99/Product/CategoryLevel/16/Common%20Conditions` (or)`http://localhost:99/Product/CategoryLevel/Common%20Conditions(or)http://localhost:99/Product/Common%20Conditions`
маршрут конфигурации составляет: routes.MapRoute( name: "Home", url: "{controller}/{action}", defaults: new { controller = "Home", action = "Index" } );
ActionResult в контроллере: `
public ActionResult CategoryLevel()
{
string ProductName = Request.QueryString["ProductName"];
ViewBag.ProductName = ProductName;
int Category = Convert.ToInt32(Request.QueryString["CategoryId"]);
ViewBag.ParentCategoryId = Category;
int ParentCategoryId = 0;
if (Request.QueryString["ParentCategoryId"] != null)
{
ParentCategoryId = Convert.ToInt32(Request.QueryString["ParentCategoryId"]);
}
Product productInstance = new Product();
IList<CategoryInfo> categories = new List<CategoryInfo>();
categories = productInstance.GetCategories(Category, true);
if (categories.Count == 0)
{
return RedirectToAction("NewProducts", "Product", new { @CategoryId = Category, ProductName = ProductName });
}
return View(categories);
}`another actionresult is`public ActionResult NewProducts(Product instance)
{
string ProductName = Request.QueryString["ProductName"];
instance.BrandName = ProductName;
int CategoryId = Convert.ToInt32(Request.QueryString["CategoryId"]);
int BrandId = Convert.ToInt32(Request.QueryString["BrandId"]);
string SortBy = Convert.ToString(Request.QueryString["sortBy"]);
if (SortBy != null)
{
Session["Sort"] = SortBy;
}
Session["NewProductsBrandId"] = BrandId;
instance.CategoryId = CategoryId;
instance.BrandId = BrandId;
instance.SortBy = SortBy;
return View(instance);
}`
возможный дубликат [ASP.NET MVC Удалить строку запроса в методе действий] (http://stackoverflow.com/questions/9672843/asp-net-mvc-remove-query-string-in-action-method) – SivaRajini
http: //stackoverflow.com/questions/9672843/asp-net-mvc-remove-query-string-in-action-method – SivaRajini