Issue: I have a list of categories with sub-categories, so when I'm sub- Clicking on the item item lists the listings for the list of entries in it with ActionLink. So when I click to create ActionLink on SubCategoryItem then the problem is passing SubCategoryId. This list lists entries without CreateActionLink but with this, it returns an error in the index view:
Object reference is not set for an instance of an object Line 6: Line 7: & Lt; P & gt; Line 8: @HtmlActionLink ("Create New", "Create", New {SubCategoryID = @ Model. SubCategoryId}) Row 9: & lt; / P & gt; Line 10:
I think I am passing nonsense reference and the question is how to avoid it? Here is my code:
Controller:
Public category entry controller: controller {public performance index} {return view (); } Public Functional Entry List (Int Sub-Carrier ID) {var Entries = Entry DLNets (Sub-Cadence ID); See Return ("_ EntryList", entries); } Create Public Functionality (IP subcategoryId) {var model = new entry (); Model.SubCategoryId = subCategoryId; See Return (Model); } [HTPOST] Create public action ranges (entry entry) {try {if (ModelState.IsValid) {var add = EntryDAL.Add (entry); Return Redirect Action ("Index"); } Return View (Entry); } Hold (exception) {see return (); }}}
Index view:
@model passwordclide.DimainModels. Shabank @ {ViewBag.Title = "Index"; } & Lt; P & gt; @html.exelink ("create new", "create", new {subsigenee = @ model. SubcategoryId}) & lt; / P & gt; @ {Html.RenderPartial ("_ EntryList", Model.EntryList);}
Partial view:
@Emelumerable & lt; PasswordCloud.Domain.Models.Entry & gt; & Lt; Table & gt; & Lt; TR & gt; & Lt; Th & gt; @ Html.DisplayNameFor (model = & gt; Model .title) & lt; / Th & gt; & Lt; Th & gt; @ Html.DisplayNameFor (model = & gt; Model username) & lt; / Th & gt; & Lt; Th & gt; @ Html.DisplayNameFor (model = & gt; model password) & lt; / Th & gt; & Lt; Th & gt; @ Html.DisplayNameFor (model => model.Url) & lt; / Th & gt; & Lt; Th & gt; @html Display Name (model = & gt; model .description) & lt; / Th & gt; & Lt; Th & gt; @ Html.DisplayNameFor (model => Model. SubCategoryId) & lt; / Th & gt; & Lt; Th & gt; & Lt; / Th & gt; & Lt; / TR & gt; @forcha (Miscellaneous items in the model) {& lt; Tr & gt; & Lt; TD & gt; @html DisplayFill (Model Isthm => Item Title) & lt; / Td> & Lt; TD & gt; @ Html.DisplayFor (ModelEystem => Item Username) & lt; / Td> & Lt; TD & gt; @html DisplayFor (Model Itam => Item Password) & lt; / Td> & Lt; TD & gt; @html DisplayForm (Model Itam = & gt; Item URL) & lt; / Td> & Lt; TD & gt; @html DisplayFlier (Model Itam => Item Details) & lt; / Td> & Lt; TD & gt; @html DisplayFor (ModelItem => Item. SBCARDID) & lt; / Td> & Lt; TD & gt; @HTMLconnect ("edit", "edit", new id / ITIID}). @ Html.ActionLink ("Details", "Description", new {id = item.Id}). @HTMLconnect ("delete", "delete", new {id = item.ID}) & lt; / Td> & Lt; / TR & gt; } & Lt; / Table & gt;
Sub-gradientItam view:
@modelimimableable & lt; Passwordclothes.domain.models. SBC & gt; @foreach (Miscellaneous items in the model) {@ Html.ActionLink (item.Name, "index", "entry", new {subCategoryId = item.SubCategoryId}, empty)}
In your index action, you never make models and pass it in view. So when it goes to your line, where you create action link where you use new {subCategoryId = @ Model.SubCategoryId}
then your model is empty. In this way you get a blank riff exception, you need to do something to fix it.
public performance index () {var model = ... return view (model); }
Comments
Post a Comment