I am developing a little MVC app.
The problem: I have a view page which has a form to add events, a form to search for events and a list of events.
It's not a big deal to place the components in single views but I need them in one page. I want a permanent form above the list of events.
The problem is that I don't know what to choice as a model object for the view. If I choice a List of events it's working perfectly with the List but not with the form. If I choice a specific Model Object fitting to the form the list hast problem.
What's the best way to handle such views with forms, lists,... ?
That's my View:
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="ViewPage<EventPlaza.Web.Models.EventsListViewModel>" %>
<%# Import Namespace="EventPlaza.Storage.Model" %>
<%# Import Namespace="EventPlaza.Web.HtmlHelpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="EventControlsContainer">
<h3>Add Event Link</h3>
<div>
<% Html.RenderPartial("AddEvent", new AddEventModel()); %>
</div>
<h3>Search for Events</h3>
<div>
<form>
Place:
<input id="elementID" name="elementID" type="text" class="inputSearch" />
Date:
<input id="datepicker" name="elementID2" type="text" class="inputSearch" />
<input id="addEvent" type="submit" value="Find Events" />
</form>
</div>
</div>
<% foreach(var product in Model.Events) { %>
<% Html.RenderPartial("EventSummary", product); %>
<% } %>
<div class="pager">
<%: Html.PageLinks(Model.PagingInfo,
x => Url.Action("List", new {page=x})) %>
</div>
</asp:Content>
This the AddEvent View Control:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EventPlaza.Storage.Model.AddEventModel>"%>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("AddEvent", "Event", FormMethod.Post)) { %>
Event Link:
<%: Html.TextBoxFor(x => x.EventLink) %>
Event Name:
<%: Html.TextBoxFor(x => x.EventName) %><br />
Place:
<%: Html.TextBoxFor(x => x.Place) %>
Starting Date:
<%: Html.TextBoxFor(x => x.StartingDate) %> <br />
End Date:
<%: Html.TextBoxFor(x => x.EndDate) %>
<input id="Submit" type="submit" value="Add Event" />
<% } %>
I strongly recommend that you should not be using the Model object from the your Domain Model directly as the type of view instead you should make a custom EventViewModel and keep three different objects corresponding to each partial view you have.
Related
I have html code and want to split it between site.master and default.aspx
When I put a full code on site.master it works, but when I took a part of code and put it in default.aspx, it doesn't work!
I just want to know how to make default.aspx reach all classes in .css files
This is my tag which cant take a class from .css
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplicationClinicASP._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<section class="hero-wrap js-fullheight" style="background-image: url('images/bg_3.jpg');" data-section="home" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<div class="container">
<div class="row no-gutters slider-text js-fullheight align-items-center justify-content-start" data-scrollax-parent="true">
<div class="col-md-6 pt-5 ftco-animate">
<div class="mt-5">
<span class="subheading">Welcome to Mediplus</span>
<h1 class="mb-4">We are here <br>for your Care</h1>
<p class="mb-4">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove.</p>
<p>Make an appointment</p>
</div>
</div>
</div>
</div>
</section>
</asp:Content>
I need to render a conditional asp:content
how can I do this please?
**if( culture=fr)**
<asp:Content ContentPlaceHolderId="altColumnContent" ID="altColContent" runat="server">
<div class="altBloc">
content 1
</div>
<!-- END: Alternative Bloc -->
</asp:Content>
**if(culture=en)**
<asp:Content ContentPlaceHolderId="altColumnContent" ID="altColContent" runat="server">
<div class="altBloc">
content 2
</div>
</asp:Content>
When, I put 2 asp:content with the same ContentPlaceHolderId i have erros.
regards
If you just want to change the content based on the culture property value, then there is no need to render different content tags, and you better move the if statement inside your and render different content inside based on the culture value?
this is a pseudo-block for demonstration
<asp:Content ContentPlaceHolderId="altColumnContent" ID="altColContent" runat="server">
<div class="altBloc">
<% if(CultureValue == FIRST_VALUE){ %>
content 1 ==> // YOUR_FIRST_CONTENT
<%} else { %>
content 2 ==> // YOUR_SECOND_CONTENT
<%} %>
</div>
</asp:Content>
My question will probably sounds dumb to most of you but I have been struggling to find out the problem. I basically have a method and a view (created by right click-> Add View).
This is my method:
public ActionResult yearlyOverview(FormCollection values)
{
return View();
}
And this is my view:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
yearlyOverview
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>yearlyOverview</h2>
</asp:Content>
The error message that I get comes from the browser:
Sys.ArgumentException: Sys.ArgumentException: Cannot deserialize. The data does not correspond to valid JSON. Parameter name: data
This is the master page code:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/css/fullcalendar.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>PS Administration</h1>
</div>
<div id="logindisplay">
</div>
<div id="menucontainer">
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("Notices", "Index", "Notice")%></li>
<li><%= Html.ActionLink("Job Positions", "Index", "JobPosition")%></li>
</ul>
</div>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
</body>
</html>
Has anybody already stumbled on this problem?
Ok my code was good but the mistake i made was to call the form using ajax.beginForm instead of a normal form, and I was trying to parse an object data that wasn't returned by the controller.
I have an mvc app which is integrated to excel workbook. I have a "Launch" button in excel which on click should launch the following website:
http://students/SubmitComments/
Here is my controller action:
public ActionResult StudentComment(string sid)
{
SubmitCommentViewModel model = new SubmitCommentViewModel ();
model.sid = sid;
TempData["model"] = model;
return View(model);
}
Here is my view:
<%# Page
Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<STU.Models.StudentCommentViewModel>"
%>
<asp:Content ID="Content4" ContentPlaceHolderID="TitleContent" runat="server">
Student Comments
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageName" runat="server">
Student Comments</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="Form1" method="post" action="/Student/StudentCommentEmail/">
<label>
Run Number: <%= Html.DisplayFor(x => x.Id) %>
</label>
<br />
<br />
<textarea name="comment" cols="40" rows="5">
Enter comments here...
</textarea><br/><br/>
<input type="submit" value="Submit Comments" /><br />
</form>
</asp:Content>
You need to host your website somewhere. http://students/SubmitComments/ is not a valid url. You can't link your excel workbook to your Visual Studio hosted site. That only works within Visual Studio. Unless you setup Visual Studio to work with IIS Express.
If you want others to use this Excel workbook then you will have to host your mvc site somewhere that is publically, or at least internally accessible.
I create a subscribe block in my page, include text box and button submit. I have a view name SubMail, this is it's content :
<%# Page Language="C#"
Inherits="System.Web.Mvc.ViewPage<Areas.Admin.Models.SubscribeMail>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>SubscribeMail</title></head>
<body>
<div style="color:#353535;font-size:small;font-family:Verdana;">
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<div class="editor-label">
Subscribe For Latest Information:
<%: Html.ValidationMessageFor(model => model.Email) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Email, new { #class =
"flathtmlcontrol", name="Email"})%>
<input type="submit" value=" Submit " class="flathtmlcontrol" />
</div>
<% } %>
</div>
</body>
</html>
I used user control to render the content to my web page, This is my user control file :
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<iframe src="<%: Url.Action("SubMail","Portfolio") %>" frameborder="0"
scrolling="no" height="70px"></iframe>
The problem is : when I clicked button submit, after page done, The control text box and submit button disappeared in my page, Until I refresh a page, the control is appear normally in my page.
Can anyone tell me , what problem is it?
The control is in an iframe, when you post the form the control contains it loads the iframe with the results of the action method the form posted to.