我想做这样的事情:
[HttpPost]
public ActionResult Index(Foo foo)
{
foo.Name = "modified";
return View(foo);
}
Run Code Online (Sandbox Code Playgroud)
但是当我的视图被渲染时,它总是具有旧值!如何修改和退货?我必须每次都清除 ModelState 吗?
我的看法:
@model MvcApplication1.Models.Foo
@using (Html.BeginForm())
{
@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Description)
<input type="submit" value="Send" />
}
Run Code Online (Sandbox Code Playgroud) 我的自动映射器有一个问题,它会引发空引用异常。
Mapper.CreateMap<People, PeopleDto>()
.ForMember(d => d.Country, opt => opt.MapFrom(o => o.Address.Country))
Run Code Online (Sandbox Code Playgroud)
问题是当 Address 为空并尝试获取地图 Address.Country 时
我试过这个:
public ActionResult Index() // << it starts here
{
return RedirectToAction("ind", new { name = "aaaaaaa" });
}
[ActionName("ind")]
public ActionResult Index(string name)// here, name is 'aaaaaaa'
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
它的工作原理..
所以,我试过这个:
[HttpPost]
public ActionResult Search(string cnpj) // starts here
{
List<Client> Client = db.Client // it always find one client
.Where(c => cnpj.Equals(c.Cnpj))
.ToList();
return RedirectToAction("Index", Client); // client is not null
}
public ActionResult Index(List<Client> Client) //but when goes here, client is always null
{
if …Run Code Online (Sandbox Code Playgroud) 当我使用'.pop'或'.remove'时,knockout会自动删除html dom中对应的元素.我的问题是:从数组中删除这些对象时,我可以像jquery的'.hide'那样做一些效果吗?
有没有办法用打字稿进行自动编译?就像在CoffeScript中使用mindscape一样?您只需保存文件,扩展程序就会编译代码.
所以我尝试在应用程序中使用工具栏作为操作栏。我试图setSupportActionBar()在由扩展类的活动托管的片段中使用该方法,该类扩展了AppCompatActivity. 由于某种原因我根本无法做getActivity().setSupportActionBar(),我只能做getActivity().setActionBar()。这样做的问题是setSupportActionBar()接受一个android.support.v7.widget.ToolbarwheresetActionBar()只接受一个 android.widget.Toolbar。这导致我的应用程序仅限于使用 Lollipop 的设备。
我发现的一个附带问题是,当尝试将工具栏的主题更改为深色时
app:theme="@style/ThemeOverlay.AppCompat.Dark"
Run Code Online (Sandbox Code Playgroud)
它不起作用。
我有两种方法:
public static int Insert<T>(this System.Data.IDbConnection connection, T param)
public static int Insert<T>(this System.Data.IDbConnection connection, IList<T> param)
Run Code Online (Sandbox Code Playgroud)
当我尝试这样的事情时:
connection.Insert(new List<Foo>());
Run Code Online (Sandbox Code Playgroud)
调用错误的方法(第一种方法).
我怎样才能使它工作?
我想知道在保存模型之前验证模型的最佳方法是什么以及优缺点.我对服务层和IValidatableObject之间存在疑问.
服务层:
public class PersonService
{
public void Insert(Person person)
{
if (!IsValid(person))
{
//something
}
}
}
Run Code Online (Sandbox Code Playgroud)
IValidatableObject:
public class Person:IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (!IsValid(this))
{
//something
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有这个自定义动作过滤器:
public class PermissionChecker: ActionFilterAttribute
{
private int _permissionId { get; set; }
private IUserSelectorService _userService { get; set; }
public PermissionChecker(int permissionId)
{
_permissionId = permissionId;
_userService = new UserSelectorService();
}
public PermissionChecker(int permissionId, IUserSelectorService userService)
{
_permissionId = permissionId;
_userService = userService;
}
public override void OnActionExecuting(HttpActionContext actionContext)
{
base.OnActionExecuting(actionContext);
}
}
Run Code Online (Sandbox Code Playgroud)
我把它设置在我的行动中:
public class HomeController : Controller
{
[PermissionChecker(1)]
public ActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用!即使在PermissionChecker的构造函数中,代码也不会传入onActionExecuting.
当我设置db.Entry(episode).State = EntityState.DeletedEF 时,会从我的列表中删除剧集并抛出一个collection was modified enumeration operation may not execute.
这是我的代码:
public async Task UpdateAsync(List<Episode> episodes)
{
using (var db = new DbContext())
{
var serie = await db.Series.Include(s => s.Episodes).SingleOrDefaultAsync(s => s.Id == id);
foreach (var episode in serie.Episodes)
{
var modifiedEpisode = episodes.Where(e => e.Id == episode.Id).SingleOrDefault();
//was deleted
if (modifiedEpisode == null)
{
db.Entry(episode).State = EntityState.Deleted;// episode is removed from serie.Episodes throwing exception
continue;
}
}
var addedEpisodes = episodes.Where(v => v.Id …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
android ×1
automapper ×1
c# ×1
generics ×1
knockout.js ×1
toolbar ×1
typescript ×1