razor

Render partial view onclick in asp.net mvc 3 project

喜夏-厌秋 提交于 2019-12-20 09:43:17
问题 In my mvc project i have a simple list of items with crud operations like this: <tbody> @{ foreach (var item in Model) { <tr> <td>@item.Title</td> <td>@item.Body</td> <td>@item.Price</td> <td><span class="EditLink ButtonLink" noteid="@item.Id">Edit</span> | <span>@Html.ActionLink("Delete", "Delete", new { id = @item.Id})</span>  |  @Html.ActionLink("Detalji", "Details", new { id = @item.Id}) </td> </tr> } } </tbody> I am wondering is it possible to render details view as partial under the

ASP.Net MVC 4 Generic Principal Difficulties

南楼画角 提交于 2019-12-20 09:37:42
问题 I am developing an ASP.Net MVC 4 web application. Previously my MVC applications have been developed using MVC 3 and with this new MVC 4 application I have just copied/ reused my authentication and authorisation code from previous applications. When a user logs into my site I do the following Account Controller public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { User user = _userService.GetUser(model.Email.Trim()); //Create Pipe Delimited string to store

Form with attachments upload and email sending

℡╲_俬逩灬. 提交于 2019-12-20 09:36:26
问题 I need to make form with a textarea and an image upload field . When somebody submit it I want it to send email (with text from textarea) with attachements (from input file upload field) to me . My simple form looks like that: @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> @Html.TextArea("Question"); <input type="file"/> <input type="submit" value="Send" /> </fieldset> } I found PHP scripts that are doing something like that, but how could I do it in ASP.NET MVC (could

Using @Html.DisplayNameFor() with PagedList

前提是你 提交于 2019-12-20 08:35:06
问题 I've been trying out the PagedList package to get paging for my index views. Everything was going well, and at the controller level everything is working fine, it only displays 5 records per page, and displays the appropriate page based on the querystring. My problem is in the view. I changed the @Model to PagedList.IPagedList so I could access the Model.HasNextPage and other properties, but now the @Html.DisplayNameFor(model => model.ItemName) are no longer working. I get this error:

Force all Areas to use same Layout

我们两清 提交于 2019-12-20 08:32:23
问题 I have the following project structure: /Views/Shared/_Layout; /Areas/Area1/Views/ControllerName/Index; ... /Areas/AreaN/Views/ControllerName/Index. Is there any way to force all areas to use the _Layout as a base layout ? Is there any way to do it without adding the _ViewStart file (for example, via the routing configuration)? See Also: How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file? 回答1: You just have to add a file named: _ViewStart.cshtml Under each area views

Force all Areas to use same Layout

社会主义新天地 提交于 2019-12-20 08:32:22
问题 I have the following project structure: /Views/Shared/_Layout; /Areas/Area1/Views/ControllerName/Index; ... /Areas/AreaN/Views/ControllerName/Index. Is there any way to force all areas to use the _Layout as a base layout ? Is there any way to do it without adding the _ViewStart file (for example, via the routing configuration)? See Also: How do I specify different Layouts in the ASP.NET MVC 3 razor ViewStart file? 回答1: You just have to add a file named: _ViewStart.cshtml Under each area views

DisplayFormat Dataannotation not working

纵然是瞬间 提交于 2019-12-20 07:29:44
问题 I have following dataannotation in my model class: [Required(ErrorMessage = "Required")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public DateTime DateOfBirth { get; set; } and when I use following in my view, I dont get validation error: <tr> <td>@Html.LabelFor(x => x.DateOfBirth, new { @class = "lbl" }, "Date Of Birth") </td> <td>@Html.TextBoxFor(x => x.DateOfBirth, new { @class = "w100 _dob" }) <br>@Html.ValidationMessageFor(x => x.DateOfBirth) </td

Can't build a chart with razor when using partial view as image src

好久不见. 提交于 2019-12-20 07:26:27
问题 How can I make chart in view with razor? Tried to use partial view ( _Chart.cshtml ): @{ var usdChart = new Chart(width: 600, height: 400) .AddTitle("Заголовок") .AddSeries( name: "USD", xValue: new[] { "1", "2", "3", "4" }, yValues: new[] { "11", "22", "33", "44" }) .Write(); } And in view: <img src="@Html.Partial("_Chart")"/> But it don't work. 回答1: With your current code, it will not render the image in the main view. Instead it render just the image. It is because when you make the

How to put a default value into a DropDownListFor?

荒凉一梦 提交于 2019-12-20 06:39:53
问题 this is my drop down list: @Html.DropDownListFor(m => m.ReportType, new SelectList(ViewBag.DateRange as List<SelectListItem>, "Value", "Text"), new { @class = "w150" }) I cannot figure out where to put the default value in there? My default value would be 'ThisMonthToDate' Any suggestions? 回答1: If you have a Model bounded to your view, I strongly recommend you to avoid using ViewBag and instead add a Property to your Model/ViewModel to hold the Select List Items. So your Model/ViewModel will

controller post action not able catch list of objects

筅森魡賤 提交于 2019-12-20 06:38:31
问题 It may duplicate question, i have searched all over but couldn't satisfied, so i am posting here question. I have object as (generated from entity framework), public partial class Usp_Sel_NotEnteredStringResources_Result { public string name { get; set; } public Nullable<int> Value { get; set; } public int StringResourceId { get; set; } public Nullable<int> LanguageId { get; set; } } and view i have created as, @{ ViewBag.Title = "Resource Entry Languagewise"; Layout = "~/Views/Shared/_Layout