Hello everybody.
I am trying to learn some ASP.NET MVC. Please bear with me but asp.net mvc is the first mvc framework i ever tried to learn. I do plan to learn more about mvc framework in different languages, but for now i got asp.net mvc.
I am fairly good with asp.net forms and love them, but would like to have another asp.net tool that allows me more freedom with HTML and JavaScript and Ajax.
The question i have is how partialViews are used ? Another question is as far as i understand from watching all the videos is that model for database, controler for action and business logic and view is for the display.
However i have a code that doesn't work, the View is pointing to the Model and not to what returning from controler (Trying to return partial view) I would really appreciate if somebody can point me in right direction and explain whats goes on.
Bellow is my simple code that doesn't work:
PartialView
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of IEnumerable (Of MvcPortfolio.Defaultdb))" %>
<p>
<%=Html.ActionLink("Create New", "Create")%>
</p>
<table>
<tr>
<th></th>
</tr>
<% For Each item In Model%>
<tr>
<td>
<%= item. %>
</td>
</tr>
<% Next%>
</table>
Model
Public Function getProjects() As List(Of portfolio_project)
Using myPortfolio As New PortfolioDataContext
Try
Dim projects = (From p In myPortfolio.portfolio_projects _
Select p).Take(5)
Return projects
Catch ex As Exception
Return Nothing
End Try
End Using
End Function
Controler: Function Index() As ActionResult
Dim myPortfolio As New Defaultdb ' my controler
Dim projectsList As List(Of portfolio_project) = myPortfolio.getProjects() 'getting list of all the projects in news
Return PartialView(projectsList) 'returning partial view.hopefully will work
End Function
and Main page:
<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="MvcPortfolio" %>
<asp:Content ID="projectsContent" runat="server" ContentPlaceHolderID="newsContent">
<%Html.RenderPartial("Indexprojects")%>
</asp:Content>
Can somebody please explain me how to make this code to work, so i will have a normal working example. I want to use partial View because i want repeating stuff to be put in user control like pieces.
Thanks in advance.