我有方法public void categoriesForm_DeleteItem(int categoryID)
in public partial class Categories_View1 : System.Web.UI.Page
。它仿照教程http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/shopping-cart的方法RemoveItem
進行建模。在response.redirect後返回
我的方法中包含以下代碼:
public void categoriesForm_DeleteItem(int categoryID)
{
/* some code ommited */
if (c != null)
{
db.Categories.Remove(c);
db.SaveChanges();
Response.RedirectToRoute("CategoriesList");
//should I add return; here?
}
else
{
ModelState.AddModelError("NotFoundError", "Category not found.");
return;
}
/* code ommited */
}
我應該Response.RedirectToRoute( 「CategoriesList」)之後添加return;
; ?
還有一個問題......我在教程中看到,方法RemoveItem
返回int,返回代碼的意圖是什麼?那個返回碼在哪裏有用?
如果該方法在'if..else'子句之後結束,則沒有。無需「返回」。如果不是,它取決於是否會有一些代碼可以清除響應或以某種方式更改(罕見)。 – haim770
從你鏈接的教程中得到的那個方法的sig是'public void RemoveItem(string removeCartID,int removeProductID)',no int returned。 – DrewJordan
@DrewJordan我一定看過int返回類型的其他方法。 :/ – Willmore