razor

ASP.NET MVC Razor, Html.BeginForm, using statement

梦想的初衷 提交于 2019-12-28 16:58:12
问题 For an ASP.NET MVC application, can someone explain to me why calls to Html.BeginForm begin with the statement @using ? Example - @using (Html.BeginForm()) { //Stuff in the form } I thought @using statements are for including namespaces. Thanks! 回答1: Using Statement provides a convenient syntax that ensures the correct use of IDisposable objects. Since the BeginForm helper implements the IDisposable interface you can use the using keyword with it. In that case, the method renders the closing

ASP.NET MVC - drop down list selection - partial views and model binding

倖福魔咒の 提交于 2019-12-28 13:56:20
问题 I'm fairly new to ASP.NET MVC and am trying to work out the best way to do this. It's probably simple but I just want to do things correctly so I thought I'd ask. Lets say I have a model that is this: Task - Id, Description, AssignedStaffMember StaffMember - Id, FirstName, LastName and in my view I want to create a new task. I make a strongly typed Razor view, and can use EditorFor to create textboxes for Description but what about AssignedStaffMember? I want a drop down list of all current

ASP.NET MVC - drop down list selection - partial views and model binding

做~自己de王妃 提交于 2019-12-28 13:56:08
问题 I'm fairly new to ASP.NET MVC and am trying to work out the best way to do this. It's probably simple but I just want to do things correctly so I thought I'd ask. Lets say I have a model that is this: Task - Id, Description, AssignedStaffMember StaffMember - Id, FirstName, LastName and in my view I want to create a new task. I make a strongly typed Razor view, and can use EditorFor to create textboxes for Description but what about AssignedStaffMember? I want a drop down list of all current

Dynamic Stylesheets Using Razor

↘锁芯ラ 提交于 2019-12-28 11:55:04
问题 How can I use Razor in CSS files? I'm using Razor View Engine for some time and I was curious about using it on style sheets. I can use Razor in <style> blocks of .cshtml files but I was wondering if I can use it in external .css files also (would like to have a .cscss format). So I googled it and found two things: The first one is LESS: "The dynamic stylesheet language". It seems easy-to-use and powerful with all the features but I need Razor-C#, really. The second is Dynamic CSS Using Razor

How to add a script in a partial view in MVC4?

房东的猫 提交于 2019-12-28 05:35:26
问题 This is the code which I have in my partial view @model Contoso.MvcApplication.Models.Exercises.AbsoluteArithmetic @using(Html.BeginForm()) { <div> <span style="width: 110px; float:left; text-align:center; font-size:2.5em;">@Model.Number1</span> <span style="width: 110px; float:left; text-align:center; font-size:2.5em;">+</span> <span style="width: 110px; float:left; text-align:center; font-size:2.5em;">@Model.Number2</span> <span style="width: 110px; float:left; text-align:center; font-size

Check for razor errors during build

▼魔方 西西 提交于 2019-12-28 04:59:12
问题 Is there a way for Visual Studio (I'm using 2010) to find errors within razor views during builds, in the same way as other code in a C# project would? It's just a pain that you can check any errors in your code and think that everything's fine, but it appears that you can't be sure about views unless you go through each one. BTW I obviously don't code in my views - I'm just talking about HTML or URL extension methods for example. 回答1: Try setting MVCBuildViews to true in your project file (i

Bundling scripts are not getting rendered

為{幸葍}努か 提交于 2019-12-28 04:31:05
问题 I am having a problem with script bundling and minification with ASP .NET I have tried all popular solution found on internet but still having the same problem. My BundleConfig.cs looks like namespace MYPROJ{ public class BundleConfig { public static void AddDefaultIgnorePatterns(IgnoreList ignoreList) { if (ignoreList == null) return; ignoreList.Ignore("*.intellisense.js"); ignoreList.Ignore("*-vsdoc.js"); ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled); ignoreList.Ignore("*

ASP.NEt MVC using Web API to return a Razor view

时光怂恿深爱的人放手 提交于 2019-12-28 03:38:07
问题 How to make the View returned by the controller and generated by Razor get the data from the api i want to keep the razor engine view and use the api the original mvc controller returns the view with the data as parameter now i want the data from the api MVC controller public class ProductController : Controller { public ActionResult Index() { return View(); } Api Controller public class ProductsController : ApiController { private ApplicationDbContext db = new ApplicationDbContext(); // GET

Convert Byte Array to image and display in Razor View

拥有回忆 提交于 2019-12-28 02:32:05
问题 I am using EF 4.1 Code First and for the sake of simplicity, let's say I have the following Entity class: public class Person { public int Id { get; set; } public string Name { get; set; } public Byte[] Image { get; set; } } I have managed to create a working Create View that allows the Addition of a Person object into the Database. But when I come to display the details for a Person, I get stuck on displaying the image. After doing some research, I have the following: // To convert the Byte

Is it OK to put JavaScript in Partial Views

核能气质少年 提交于 2019-12-28 01:52:08
问题 I’m working on the web app where the main page contains two parts: the constant block which is always visible and the info-block made up by one of 3 partial views. Each of the partial views appears as a result of AJAX request and is loaded just once (after that switching windows is provided by jquery). It works well but I’ve faced with one problem. The html-code of partial views contains js functions that are used in the constant block and in the info-block as well. When the page is loaded,